Reputation: 1043
My application have two activities, say MainActivity
and SecondActivity
. Main activity is declared as android:launchMode="singleInstance"
and its orientation is always portrait
. Second activity is always has landscape
orientation.
In some devices, everything is alright and in task manager there is only one instance of my app, but in some devices (like Samsung S7), when I launch SecondActivity
, there will be two instances of my app in task manager like this image:
My guess is that something is wrong with the launchMode
of the MainActivty
but I need it to be singleInstance
. Any suggestion?
EDIT:
MainActivity in manifest:
<activity
android:name=".Activities.MainActivity"
android:screenOrientation="portrait"
android:launchMode="singleInstance"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and second:
<activity
android:name=".Activities.SecondActivity"
android:screenOrientation="landscape" />
launching code:
Intent intent = new Intent(getActivity(),
intent.putExtra("VideoUri", filmGet.getOutput().getData().getFilmTrailer());
startActivity(intent);
If it helps, I launch SecondActivity
from a fragment.
Upvotes: 2
Views: 2041
Reputation: 1043
So, after reading @sharan comment and some googling, it made me to read some google documents. According to docs, there isn't any difference between android:launchMode=singleInstance
and android:launchMode=singleTask
but one. They both make your activity singleton
and so you will never have two instances of it. The only difference between them is that singleInstance
will prevent the task from attaching any other activity while singleTask
has not this limitation. Any other things about them are the same.
So, for anyone who is reading this post, I'll recommend you to never use singleInstance
launch mode unless you exactly need what it has. Because if you have only one activity in your app, then there will be no differences between singleInstance
and singleTask
. And if you have more than one activity, then I'll recommend you to all of your activities belong to one task.
In short, change singleInstance
to singleTask
and you are go.
Upvotes: 5