2013-06-26 39 views
0

我與一個彈出(活動自定義對話框)顯示任務的工作,我想刪除的活動,我表明當我按下home鍵

這將是來自於作爲per time schedule這就是爲什麼我用services服務觸發廣播接收器BroadCast Receiver trigger my this activity class其中包含對話框

所有工作良好的彈出窗口都按照時間表安排。

問題:

當我的應用程序是接近我按Home鍵那段時間我的應用程序與彈出屏幕一直開着。

我想顯示所有條目,如android:launchMode="singleTask","android:noHistory="true"等等。

我認爲總是與最近的活動數據疊加,但我使用完成()在poup確定點擊。

請給我一些指導。

+0

我不確定這個...但是當你按下home按鈕的時候調用onPause()方法......如果你不想關閉你的活動。在onPause()中寫入你的代碼也許它會起作用... – Amsheer

+0

onCreate(),OnResume()所有的調用。但我需要在主屏幕上按下這個屏幕。 – Harshid

+0

然後在暫停()(使用....(完成()))中寫入退出代碼 – Amsheer

回答

0

很多googling我找到了把戲。

檢查if popup click然後

finish(); 
startActivity(new Intent(this,MainActivity.class)); 

否則

ShowPopup() 

感謝@Aarun和@約翰·卡特JC的幫助我。

1

使用時要顯示主屏幕

Intent setIntent = new Intent(Intent.ACTION_MAIN); 
setIntent.addCategory(Intent.CATEGORY_HOME); 
setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(setIntent); 
+0

這不適合我。 – Harshid

1

我認爲你可以使用你可以使用FLAG_ACTIVITY_CLEAR_TOP

FirstActivity這個意圖是在應用程序中的第一個活動:

public static void home(Context ctx) { 
    if (!(ctx instanceof FirstActivity)) { 
     Intent intent = new Intent(ctx, FirstActivity.class); 
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     ctx.startActivity(intent); 
    } 
} 

如果你想退出整個應用程序,這有助於你在 那。

public static void clearAndExit(Context ctx) { 
    if (!(ctx instanceof FirstActivity)) { 
     Intent intent = new Intent(ctx, FirstActivity.class); 
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     Bundle bundle = new Bundle(); 
     bundle.putBoolean("exit", true); 
     intent.putExtras(bundle); 
     ctx.startActivity(intent); 
    } else { 
     ((Activity) ctx).finish(); 
    } 
} 

我真的希望這會有所幫助。

+0

謝謝Aarun讓我試試。 – Harshid

+0

嘿Aaruin我在對話中如何使用? – Harshid

+0

此代碼用於任何活動中的任何地方,只需調用您要完成活動堆棧的方法,... – Aarun

相關問題