I have 3 activities (MainActivity, TwitterActivity, WebBrowserActivity). WebBrowserActivity uses for showing web info from twitter.
Manifest: 1.
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
2.
<activity
android:name=".TwitterActivity"
android:label="@string/app_name"
android:launchMode="singleInstance" >
<!-- Used for OAuth callback -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="callback"
android:scheme="x-bker-oauth-twitter" />
</intent-filter>
</activity>
3.
<activity android:name=".TwitterWebBrowser" />
Starting twitter:
Intent myIntent = new Intent(mContext, TwitterActivity.class);
mContext.startActivity(myIntent);
When twitt is posted I close TwitterActivity (using finish(); method) and MainActivity shows. Than I press Home Button and goes to Android, than press home button and press my app icon, and I goes to TwitterActivity, but I need to go to MainActivity. How do this?
It is only on android version 2.3.7 and below.
In your manifest entry for the TwitterActivity, change android:launchMode="singleInstance"
to android:launchMode="singleTop"
.
I think you are setting launchMode
because you want to be able to jump out to the Twitter app or web page to authorize the user from TwitterActivity, and then return back to the same instance of your TwitterActivity when done. In that case, TwitterActivity will be at the top of your task stack, so singleTop
will tell the system to reuse it.
The problem with singleInstance
is that it makes the activity the only activity in the task, which probably explains why the recents menu is launching the TwitterActivity. (more info in activity element docs).
If you really need to use singleInstance
, you should consider assigning it to its own task and excluding it from recents, for example (use your own name for taskAffinity
):
<activity
android:name=".TwitterActivity"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:taskAffinity="com.example.twitter"
android:excludeFromRecents="true">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.