Eyn*_*chl 2 navigation android back android-activity
我正在开发一个包含 3 个活动的应用程序。Main 和另外两个,可以从 Main 启动。两者都有一个 Toolbar Back-Button,它通向 Main,它在 back stack 上等待。在这种情况下会出现问题:
从 Main 启动 Activity B。- 将应用程序留在主屏幕 - 稍等片刻,做一些其他事情,...(或强制关闭应用程序设置中的应用程序) - 使用应用程序概览重新启动它(应用程序在活动 B 中重新启动) -按工具栏后退按钮 -> 应用程序关闭。
在这一点上,我预计它会回到 Main,但它没有。
显现:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- ACTIVITIES -->
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ReminderActivity"
android:label="Reminder"
android:launchMode="singleTask"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="yyyy.yy.yyyy.MainActivity" />
</activity>
<activity
android:name=".PreferencesActivity"
android:label="Preferences"
android:launchMode="singleTask"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="yyyy.yy.yyyy.MainActivity" />
</activity>
<!-- RECEIVERS -->
<receiver android:name="yyyy.yy.yyyy.StartupReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name=".NotiDeactivateReceiver"></receiver>
<!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
Run Code Online (Sandbox Code Playgroud)
活动: 我使用了在 stackoverflow 上找到的代码
public void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar2);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
Run Code Online (Sandbox Code Playgroud)
我还尝试使用 NavUtils 来“向上”。一样的效果。
我在我的场景中尝试了一些其他应用程序,我注意到,当它们被踢出内存(或被我使用应用程序设置手动杀死)时,它们会在主活动中重新启动。我的重新启动了我离开它的点,但可能没有后退堆栈。
你能帮我弄清楚这里出了什么问题吗?
尝试在清单中替换 MainActivity 的属性
android:launchMode="singleInstance"
Run Code Online (Sandbox Code Playgroud)
到
android:launchMode="singleTop"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1885 次 |
| 最近记录: |