In my app, I am using the IntentService class to start another activity in the background. But the issue I got is that suppose from the IntentService class I start my activity, which opens my activity, after that I don’t close my activity. Then I notice that when IntentService class again wants to start my same activity it is not called as the same activity is not close.
So, my question is: How can I start the same activity again and again whether it is open or close from the IntentService class?
Code in IntentService class
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));
}
}
use launchMode tag in manifest file
it will not create a different instance of activity if already available..
see this link launchMode for better understanding