A
A
Alexey2013-06-11 10:13:46
Java
Alexey, 2013-06-11 10:13:46

Only one copy of the Activity or one copy of the application?

I ran into a problem that you can run multiple copies of one Activity (application) if you start the application from different "places". It turns out that you close it, and under it is another one of the same. I was able to launch up to 3-4 identical pieces.
Well, roughly speaking, the first time I launched the application as expected. The second time I launched it from the Wakelock Detector, by clicking on it there "open". A new copy of the application has started.
So, how to avoid this? Do crutches with a check that I'm already running or is there some normal method?
The Activity has the flag android:launchMode="singleTop", it is launched in the application like this:

Intent in = new Intent(this, chatActivity.class);
in.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(in);

And from the application everything is ok. But when different copies of the application ... trouble.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
serso, 2013-06-11
@alexxxst

One application (with one package name) cannot be launched several times - the VM is launched once. Activity, indeed, you can create a lot - study launchMode in AndroidManifest. SingleTop should suit you, but you need to set it not programmatically (like you do), but in the manifest.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question