[英]intent starts again after finish
我使用一個按鈕退出我的應用程序,但是,當我退出它並按下最近的應用程序按鈕(下圖)並通過灰屏重新進入我的應用程序時,而不是從主活動啟動應用程序,它從最近的活動和崩潰,因為它有 bo 數據.. 即使應用程序崩潰,當我再次按下灰色活動時,它再次打開第二個活動並再次崩潰..
灰屏圖片( https://ibb.co/TqPnXJR )
我該如何解決當用戶單擊灰屏時它將啟動主要活動的問題?
這是我的代碼:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Stop Navigation ");
builder.setMessage("Are you sure you want to stop navigation?");
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
exitButtonPressed = true;
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
//finishAffinity();
//System.exit(0);
//finishAndRemoveTask();
//android.os.Process.killProcess(android.os.Process.myPid());
// I TRIED ALL THE ABOVE BUT ITS ITS NOT WORKING..
}
});
謝謝 !!
編輯:
當點擊灰色方塊時,它會激活 OnResume..
我注意到每次我刪除我的任務並通過我的前台服務進入它發生的第二個活動時。 我認為它與未決的意圖有關。
這是我待處理的意圖代碼:
Intent i = new Intent(getApplicationContext(), MapsActivity.class);
i.putExtra("AddressBackground22", mAddress);
i.putExtra("AddressType22", mAddressType);
i.putExtra("AddressLatBackground22", destinationLat);
PendingIntent activityPendingIntent = PendingIntent.getActivity(this, 25, i, 0);
NotificationCompat.Action action2 = new NotificationCompat.Action(R.drawable.ic_cancel, getString(R.string.remove_location_updates), servicePendingIntent);
NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_launch, getString(R.string.launch_activity), activityPendingIntent);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
Notification notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setContentTitle("App is running in background")
.addAction(action)
.addAction(action2)
.setColor(getColor(R.color.foreGroundBackgroundColor))
.setPriority(NotificationManager.IMPORTANCE_HIGH)
.setCategory(Notification.CATEGORY_SERVICE)
.setSmallIcon(R.drawable.applogo)
.build();
你為什么使用
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
只需調用
finish();
點擊按鈕
YourActivity.this.finish();
您應該在完成活動之前關閉對話框
Dialog.dismiss();
希望可能會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.