這與所有「給我的類似」問題都非常不同。我工作的一個應用程序,當用戶註冊後在一個活動的帳戶稱爲SignUpActivity,我帶他們去使用下面的代碼的另一項活動叫UserProfileActivity:在一項活動中按下手機後退按鈕可進入另一項尚未在Android之前初始化的活動
SignUpActivity:
Intent userProfileIntent = new Intent(SignUpActivity.this, UserProfileActivity.class);
startActivity(userProfileIntent);
finish();
現在,在UserProfileActivity中,如果我按下後退按鈕,它會將我帶到一個活動,該活動在應用程序生命期內從未被訪問/實例化,名爲PartyListActivity。
UserProfileActivity:
public class UserProfileActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_profile);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
所以我的問題是爲什麼,當我按回到UserProfileActivity,它回去PartyListActivity,當我從來沒有對PartyListActivity過嗎?清單文件中是否存在指示此行爲的內容?
編輯
的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.package">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:name=".LoginActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SignUpActivity"
android:label="@string/title_activity_sign_up" />
<activity
android:name=".PartyListActivity"
android:label="@string/title_activity_party_list"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".UserProfileActivity"
android:label="@string/title_activity_user_profile"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".FriendsActivity"
android:label="@string/title_activity_friends"
android:theme="@style/AppTheme.NoActionBar" />
</application>
</manifest>
你什麼時候打電話給PartyListActivity?請給我看看你的清單! – redAllocator
您可以使用adb打印活動backstack'adb shell dumpsys活動包' –
@redAllocator我在其他方法中調用PartyListActivity。但是在我正在複製的情況下,這些方法從未被稱爲。 AyushKhare什麼時候可以運行? – Michael