Android 按下后退按钮并更改方向时,重新启动而不是重新创建
我有两个活动,A和ba是它们的父活动,它们都是在XML源上定义的静态片段 查找我的问题的步骤: 活动A开始活动B。 在活动B中,我按下后退按钮并返回到活动A。 我旋转我的设备,然后方向改变,但是现在调用onRestart而不是onCreate,更奇怪的是,活动B的片段是在活动A上创建的。 恢复。在backbutton和方向更改之后,B内容视图将显示给我,并带有一个操作栏???。 注: 如果我按home(主页)按钮而不是back(后退)按钮,活动也会正常工作。 发生这种情况时,活动A中的操作栏将按其应有的方式显示。 在开始活动B并按下后退按钮之前,屏幕旋转也可以工作。 我没有使用singleTop或其他maninfest属性来进行这些活动 我怎么了?对不起,我的英语不好 活动A:Android 按下后退按钮并更改方向时,重新启动而不是重新创建,android,android-fragments,back-button,activity-lifecycle,orientation-changes,Android,Android Fragments,Back Button,Activity Lifecycle,Orientation Changes,我有两个活动,A和ba是它们的父活动,它们都是在XML源上定义的静态片段 查找我的问题的步骤: 活动A开始活动B。 在活动B中,我按下后退按钮并返回到活动A。 我旋转我的设备,然后方向改变,但是现在调用onRestart而不是onCreate,更奇怪的是,活动B的片段是在活动A上创建的。 恢复。在backbutton和方向更改之后,B内容视图将显示给我,并带有一个操作栏???。 注: 如果我按home(主页)按钮而不是back(后退)按钮,活动也会正常工作。 发生这种情况时,活动A中的操作栏将按
public class ChoosePaymentMethodActivity extends Activity{
private Checkout checkout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ToFinishReceiver.registerActivity(this);
setContentView(R.layout.activity_choose_payment_method);
checkout = getIntent().getParcelableExtra(Checkout.PARCEL_KEY);
}
//defined on XML
public void onClickOnDelivery(View v){
nextStep(DeliveryCheckoutActivity.class);
}
private void nextStep(Class<?> clazz){
Intent intent = getIntent();
intent.putExtra(Checkout.PARCEL_KEY, checkout);
intent.setClass(this, clazz);
startActivity(intent);
}
}
我的男朋友
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.lexsis.crazyapp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<application
android:name=".CrazyApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Theme.Home" >
</activity>
<activity
android:name=".requestfood.request.ChoosePaymentMethodActivity"
android:label="@string/payment_method"
android:parentActivityName=".MainActivity"
android:theme="@style/Theme.Purple" >
</activity>
<activity
android:name=".requestfood.request.DeliveryCheckoutActivity"
android:label="@string/payment"
android:parentActivityName=".requestfood.request.ChoosePaymentMethodActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.Purple" >
</activity>
</application>
</manifest>
我找到了问题的根源 我开始活动B的目的是为了活动A
private void nextStep(Class<?> clazz){
Intent intent = getIntent();
intent.putExtra(Checkout.PARCEL_KEY, checkout);
intent.setClass(this, clazz);
startActivity(intent);
}
相反,我现在使用的是:
private void nextStep(Class<?> clazz){
Intent intent = new Intent(this, clazz);
intent.putExtras(getIntent());
intent.putExtra(Checkout.PARCEL_KEY, checkout);
startActivity(intent);
}
给我们你的源代码
private void nextStep(Class<?> clazz){
Intent intent = new Intent(this, clazz);
intent.putExtras(getIntent());
intent.putExtra(Checkout.PARCEL_KEY, checkout);
startActivity(intent);
}