从广播接收器Android的杀进程 [英] Android kill process from broadcast receiver

查看:149
本文介绍了从广播接收器Android的杀进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找杀死我的应用程序的活动,当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.

这篇关于从广播接收器Android的杀进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆