startActivity()在BroadcastReceiverclass中不起作用

时间:2015-02-19 11:34:20

标签: android

我的代码是:

Intent lockintent = new Intent();         
lockintent.setClassName("com.example.lalitha.s1",
                         "com.example.lalitha.s1.WipeActivity");
context.startActivity(lockintent);
mDPM = DevicePolicyManager)context.getSystemService(                                      Context.DEVICE_POLICY_SERVICE);
mDeviceAdmin = new ComponentName(context, DeviceAdminSample .class);
boolean active = mDPM.isAdminActive(mDeviceAdmin);
   if (active) {
        mDPM.lockNow();
    }
   else{
       Toast.makeText(context, "not locked", Toast.LENGTH_LONG).show();
   }

context.startActivity未执行 如果我省略那么它的显示设备"没有锁定"

1 个答案:

答案 0 :(得分:0)

替换此位:

Intent lockintent = new Intent();         
lockintent.setClassName("com.example.lalitha.s1",
                     "com.example.lalitha.s1.WipeActivity");

Intent lockintent = new Intent(context, WipeActivity.class);
lockintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

但请记住,Toast消息仍将显示。