2012-07-07 63 views
3

在我的應用程序中,我使用IntentService類在後臺啓動另一個活動。但我得到的問題是,假設我從IntentService課開始了我的活動,開啓了我的活動,之後我不關閉活動。然後我注意到,當IntentService類再次想要開始我的同一活動時,它不會被調用,因爲同一活動不會關閉。所以我的問題是我怎樣才能從IntentService課程開始或關閉一次又一次地開始相同的活動。從IntentService類中調用Activity的問題

守則IntentService類

public class AlarmService extends IntentService 
{  

    public void onCreate() { 
     super.onCreate(); 
    } 

    public AlarmService() { 
     super("MyAlarmService"); 
    } 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
     super.onStartCommand(intent, startId, startId); 
     return START_STICKY; 
    } 

    @Override 
    protected void onHandleIntent(Intent intent) {   
     startActivity(new Intent(this, 
      AlarmDialogActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 
    }  
} 

回答

6

清單文件使用launchMode標籤

<activity 
     android:name=".ActivityName" 

     android:launchMode="singleTask" /> 

也不會,如果已有創建活動的不同實例..

看到這鏈接launchMode以便更好地瞭解

+0

它的工作......謝謝你的回覆 – AndroidDev 2012-07-07 07:16:48

+0

可以幫助我解決這個問題http://stackoverflow.com/questions/11373130/how-to-get-foldername-and-filename-from-the-directorypath – AndroidDev 2012-07-07 07:26:13

相關問題