What I would do, without knowing exactly how that code works, try and see if it is what you need or not.
I would not start the activity in IntentService
, I would do the following:
Where you now start the activity, you would call a broadcast
Intent intent = new Intent("cerrarActivity");
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
And then in the activity that you want to close:
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// aqui abres la nueva activity y cierras la actual
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
};
@Override
public void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter("cerrarActivity")); // register broadcast
}
@Override
public void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver); // unregister broadcast
}