Mic*_*ans 7 java android android-ndk android-manifest android-layout
我创建了我的锁屏应用程序,它由一个短信驱动..我有ListenSMS类,总是收听传入的短信.这是代码:
for (SmsMessage message : messages) {
String tempMessage[] = message.getDisplayMessageBody().toString().split(" ");
//checking command dan password
if (tempMessage[0].toString().equalsIgnoreCase("andro-lock") && tempMessage[1].toString().equals(tempPassword.toString())) {
//Toast.makeText(ListenSMSservice.this, "Menjalankan command andro-lock", Toast.LENGTH_LONG).show();
openDatabase();
updateStatusL();
Intent myIntent = new Intent(ListenSMSservice.this,LockScreenForm.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(myIntent);
}
else if (tempMessage[0].toString().equalsIgnoreCase("andro-unlock") && tempMessage[1].toString().equals(tempPassword.toString())) {
//Toast.makeText(ListenSMSservice.this, "Menjalankan command andro-unlock", Toast.LENGTH_LONG).show();
openDatabase();
updateStatusNL();
Intent myIntent = new Intent(ListenSMSservice.this,LockScreenForm.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle myKillerBundle = new Bundle();
myKillerBundle.putString("kill","1");
myIntent.putExtras(myKillerBundle);
getApplication().startActivity(myIntent);
}
}
Run Code Online (Sandbox Code Playgroud)
如果ListenSMS服务收到一个andro-lock命令,它将转到lockscreen.java 并将kill在收到命令时使用intent extra(putExtra)转到lockscreen.java andro-unclock.这是我的lockscreen.java:
public class LockScreenForm extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.lockscreen);
Bundle extra = getIntent().getExtras();
if (extra == null) {
return;
}
//Toast.makeText(this, extra.getString("kill"), 1).show();
else if(this.getIntent().getExtras().getString("kill").equalsIgnoreCase("1")) {
try {
Toast.makeText(this, "extra accepted", 1).show();
finish();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, e.getMessage(), 1).show();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我的ListenSMS服务收到"andro-unlock"命令时,我想关闭我的locksreen.java ,所以我把额外的意图"杀死"并在lockscreen.java中检查它.这个lockscreen.java可以检查额外的意图,并可以显示"额外接受"的吐司,但可以使用finish()关闭锁屏活动.
我现在的假设是Intent.FLAG_ACTIVITY_NEW_TASK重复锁定活动.因此它将创建一个双锁屏活动,finish方法正在关闭另一个启动的lockscreen.java Intent.FLAG_ACTIVITY_NEW_TASK.这是唯一的假设.我错了吗?请指正.
有谁知道如何解决我的问题?我真的希望"andro-unlock"命令可以关闭锁屏活动,并且需要它适用于我的大学最终项目.请帮忙.
来自http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK:
When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in. See FLAG_ACTIVITY_MULTIPLE_TASK for a flag to disable this behavior.
Run Code Online (Sandbox Code Playgroud)
我希望你的问题出在其他地方。我建议让锁屏 Activity 注册一个 BroadcastReceiver,然后当收到解锁消息时发送一个 BroadcastReceiver 将捕获的 Intent。然后 Activity 就可以干净地退出。
| 归档时间: |
|
| 查看次数: |
1421 次 |
| 最近记录: |