2013-07-11 33 views
5

我有一個啓動風格的應用程序。一旦用戶啓動應用程序,時鐘開始滴答滴答,經過一段時間後,用戶將返回到我的應用程序的主要活動並通知時間已到。強迫我的活動前景?

爲了做到這一點,我有一個AsyncTask,它的doInBackground定期檢查已經過了多少時間(這部分工作正常)。然後:

protected void onPostExecute(String s) { 
     super.onPostExecute(s); 
     Intent intent = new Intent(getApplicationContext(), HomeScreenMain.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
     startActivity(intent); 
    } 

唯一的問題是,它使我的應用程序保持在後臺,但我認爲正確的活動啓動。所以我的問題是,如果時間到期了,我不僅可以開始此活動,而且可以將其展示在用戶可能已從我的應用程序內啓動的任何應用程序的前端?

+2

你願意發佈你的解決方案作爲你的問題的答案(並可能接受它),以便其他人將它視爲「已回答」。你甚至可能會得到一些upvotes ;-) – eskatos

+0

如何調用onResume?我相信它應該把應用程序在前臺,但我不認爲這是一個好主意,因爲你的應用程序可以隨時彈出。 –

回答

0

更換我原來的代碼如下:

protected void onPostExecute(String s) { 
    super.onPostExecute(s); 
    Intent intent = new Intent(); 
    intent.setClass(HomeScreenMain.this, HomeScreenMain.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    getApplicationContext().startActivity(intent); 
} 

的伎倆。