我期待在我目前正在研究的一個小應用程序中出現相當奇怪的行爲。安卓在瀏覽器上的後退鍵不會啓動以前的活動
該應用程序由兩個活動組成。從第一項活動中,我通過意向啓動webbbrowser。當我在瀏覽器中按下後退鍵時,即使我在啓動之前先手動關閉了應用程序,它也會返回到SECOND活動。
1)第一活動
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mWebShopURL));
startActivity(intent);
第一活動啓動第二活動這樣
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
Bundle b = new Bundle();
b.putString("product", mProduct);
intent.putExtras(b);
startActivity(intent);
2)第二活動 - >第一活動
onBackPressed();
AndroidManifest
<activity
android:name=".FirstActivity"
android:label="@string/app_name"
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=".SecondActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
你在哪裏放置了「第一次活動啓動第二次活動」這樣的代碼? – Nick
Thx爲您的答覆。它位於View.OnClickListener中,當用戶單擊一個簡單的按鈕時就會啓動。 – felix