MainActivity->单击按钮-> SecondActivity->单击按钮(将手机保持在横向状态,但此时屏幕内容实际上以纵向显示)->屏幕内容将暂时横向显示,并将还原为几秒钟内就可以完成画像。
似乎发生了onConfigurationChanged,但实际上并未调用onConfigurationChanged()方法。相反,MainActivity被销毁并重新创建。
问题是:
为什么运行(将手机横向放置,但此时屏幕内容实际上是纵向显示)
1.Toast.makeText()。show();
2.finish();
然后屏幕似乎将发生在ConfigurationChanged上,然后销毁并重新创建MainActivity。如下面的登录。
但是如果我将顺序更改为
1.finish();
2.Toast.makeText()。show();
它将正常工作,不会破坏,而是重新创建MainActivity。预先感谢,如果您有兴趣,我将不胜感激。
I/ContentCatcher: Interceptor : Catcher list invalid for com.android.toastdemo@com.android.toastdemo.MainActivity@198995995
Interceptor : Get featureInfo from config pick_mode
E/MainActivity: onCreate
E/MainActivity: onStart
E/MainActivity: onResume
E/MainActivity: onPause
I/ContentCatcher: Interceptor : Catcher list invalid for com.android.toastdemo@com.android.toastdemo.SecondActivity@231501910
Interceptor : Get featureInfo from config pick_mode
E/SecondActivity: onCreate
E/SecondActivity: onStart
E/SecondActivity: onResume
D/OpenGLRenderer: endAllActiveAnimators on 0x72d5594400 (RippleDrawable) with handle 0x72e2997760
E/MainActivity: onStop
I/Toast: Show toast from OpPackageName:com.android.toastdemo, PackageName:com.android.toastdemo
E/SecondActivity: onPause
E/MainActivity: onDestroy
I/ContentCatcher: Interceptor : Catcher list invalid for com.android.toastdemo@com.android.toastdemo.MainActivity@246614170
Interceptor : Get featureInfo from config pick_mode
E/MainActivity: onCreate
E/MainActivity: onStart
E/MainActivity: onResume
D/OpenGLRenderer: endAllActiveAnimators on 0x72c7e8f800 (RippleDrawable) with handle 0x72e2922720
E/SecondActivity: onStop
onDestroy
E/MainActivity: onPause
E/MainActivity: onStop
onDestroy
I/ContentCatcher: Interceptor : Catcher list invalid for com.android.toastdemo@com.android.toastdemo.MainActivity@185521768
Interceptor : Get featureInfo from config pick_mode
E/MainActivity: onCreate
E/MainActivity: onStart
E/MainActivity: onResume
公共类MainActivity扩展了AppCompatActivity {
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button) findViewById(R.id.button)).setText("First");
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, SecondActivity.class));
}
});
Log.e(TAG, "onCreate");
}
... some log
}
公共类SecondActivity扩展了AppCompatActivity {
private static final String TAG = "SecondActivity";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_main);
((Button) findViewById(R.id.button)).setText("Second");
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(SecondActivity.this, "Toast Something", Toast.LENGTH_SHORT).show();
finish();
}
});
Log.e(TAG, "onCreate");
}
... some log
}
<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/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="nosensor">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".SecondActivity"
android:screenOrientation="nosensor"/>
</application>