I have an activity with an UDP socket on a port. If I press the Home button the activity goes in background, OnPause() and OnStop() methods are called. Now I want to resume my activity when I receive some UDP packet. Reading the other posts I understand I have to:
- declare the activity as
android:launchMode="singleTask"(orsingleInstance) - Then, when I want to resume the activity:
Intent intent = new Intent(this.getApplicationContext(), myActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
This solution does not work form me. The call to startActivity(intent) does not show my activity on foreground and onResume() is not called.
The following flags do the job but I don't want to clear the task and restart a new one.
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);