Java – prevent duplicate activities
So I'm both a novice in Java and creating Android applications, but not a novice in programming I've read most of developer android. COM, but I haven't found this yet:
I want to make sure that an activity does not run multiple times at the same time So we have a task like this: activity a) start the tabactivity activity b) Click to open the listview activity C), which is the interface of the media object
Now, whenever someone presses the back button in C (this may be a possible thing because they want to listen to a flowing 1 hour long MP3), and then press another list item instead of returning to C, C opens the second time, and the two streams are playing Of course, I just want an instance of C running, and I want to click the list item a second time to bring C back to the front This is also useful for notifying intent
I've been making a mess of signs (especially flag_activity_new_task, flag_activity_clear_top and flag_activity_reorder_to_front), but so far I haven't succeeded
If someone can help me, I can focus on my next challenge - making it a real feed reader: P
Thank you in advance,
Solution
You need to mark your activity as "singletask" or "singleinstance" in the list I don't remember the exact difference between 2, but either do what you want Singleinstance just does something different from the stack
Example:
<activity android:name="MainActivity" android:launchMode="singleInstance"></activity>
You can use onnewintent() to process a new call to startactivity() from the same activity instance,