2011-10-07 77 views
3

我有一個splash screenGridView,simple text view如何殺死一個活動

在應用程序啓動後,我將顯示啓動畫面,之後我稱之爲「finish()」以退出活動,然後啓動「GridView」活動。

1st page: Grid View having 4 buttons, let's call it Home page.. 
2nd page: On click of 1st button, SAME grid view is called. But this time, there are 5 buttons. 
3rd page: On click of 1st button, same grid view is called. This time there are 3 buttons. 
4th page: On click of 1st button, it opens a simple text view, which has a text box and an "Home" button. 

在主頁上,當我點擊後退按鈕,我希望應用程序退出,或關閉... 但由於第1,第2,第3頁仍然在堆棧中,我不能就這麼退出應用程序。

在我的主屏幕上,如果我點擊平板電腦的「主頁」按鈕,應用程序將退出。當我從「應用程序」選項再次啓動應用程序時,會顯示先前顯示的屏幕,而不是啓動屏幕!

我希望它顯示啓動畫面。

+0

好的問題,如果你不介意,然後搜索在谷歌閃屏example.you可以找到你的答案 – Google

回答

1

調用新的屏幕,應用程序得到恢復。所以下次打開相同的頁面。這種用途

@Override 
protected void onRestart() { 
    // TODO Auto-generated method stub 
    super.onRestart(); 
    startActivity(new Intent(Activity1.this,spalshscreen.class)); 
} 

上重新啓動,你也可以使用Intent.FLAG_ACTIVITY_CLEAR_TOP如果活動是在棧重啓標誌。

+0

謝謝,那麼我不知道onRestart。問題解決了。感謝您的評論。 – Pallavi

+0

嘿,對不起,我有點忙碌的死線。稍後會和你談談嗎? – Pallavi

2

嘗試在開始活動時使用FLAG_ACTIVITY_NEW_TASK。使用

Intent intent = new Intent(activity,secondActivity.class); 
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
activity.startActivity(intent); 

當你點擊主頁按鈕清單中該活動

+1

開始你的活動是這樣的:Intent intent = new Intent(getApplicationContext(),Activity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); –

+0

它不會去第二頁,這是相同的「網格視圖」,但不同的按鈕... – Pallavi

1

試試這個代碼在你的活動 -

@Override 
protected void onDestroy() { 
    android.os.Process.killProcess(android.os.Process.myPid()); 
} 

當您從您的應用程序退出,你的應用程序實際上並沒有被破壞。如果你銷燬你的進程,所有的子進程(你的所有子線程)都將被銷燬。

+0

問題已經解決了,我在上面的答案中加了一個複選標記,但是謝謝:) – Pallavi