从广播接收器Android的杀进程接收器、进程、Android

由网友(淑女不是我的范儿)分享简介:我在找杀死我的应用程序的活动,当USB断开时,我有一个广播接收器和所有的设置和工作的罚款Hi i'm looking to kill an activity in my application when the usb is disconnected i have a broadcast receiver and a...

我在找杀死我的应用程序的活动,当USB断开时,我有一个广播接收器和所有的设置和工作的罚款

Hi i'm looking to kill an activity in my application when the usb is disconnected i have a broadcast receiver and all set up and working fine

public class USBOff extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Intent intent1 = new Intent(context, SdcardOff.class);
    startActivity(intent1);
    finish();
    }
 }

这code但告诉我,创建到终点的方法和startActivity方法需要什么?这是为什么不工作与我的问题谢谢你的帮忙

This code however tells me that the finish method and startActivity methods need to be created? why is this not working thank you for any help with my problem

推荐答案

startActivity 是一个上下文方法,而不是一个BroadcastReceiver方法。 完成是一种活动方式。试试这个:

startActivity is a Context method, not a BroadcastReceiver method. finish is an Activity method. Try this:

context.startActivity(intent1);

您不能调用完成从一个BroadcastReceiver。

You can't call finish from a BroadcastReceiver.

阅读全文

相关推荐

最新文章