1、Activity的生命周期:
开 → 关:onCreate → onStart → onResume → onPause → onStop → onDestroy
开 → 后台:onCreate → onStart → onResume → onPause → onStop
后台 → 开:onRestart → onStart → onResume
2、Activity切换屏幕时的生命周期:
A、默认情况下,
竖 → 横:
onCreate → onStart → onResume → onSaveInstanceState → onPause → onStop →
onDestory → onCreate → onStart → onRestoreInstanceState → onResume
横 → 竖:同上
B、在Menifest中设置Activity属性android:configChanges=”orientation”
竖 → 横:同上
横 → 竖:
onSaveInstanceState → onPause → onStop → onDestory → onCreate → onStart →
onRestoreInstanceState → onResume → onConfigurationChanged
C、在Menifest中设置Activity属性android:configChanges=”orientation|keyboardHidden”
竖 → 横:
onConfigurationChanged()
横 → 竖:
onConfigurationChanged → onConfigurationChanged
3、Activity的跳转
A、Intent intent = new Intent();
intent.setClass(.this, .class);
this.startActivity(intent);
B、Intent intent = new Intent(.this, .class);
this.startActivity();
4、Activity的传参
A、发送:
Intent.putExtra(“key”, “value”);
接收:
Intent intent = this.getIntent();
Bundle bun = intent.getExtras();
String str = bun.getString(“key”);
B、发送:
Bundle bun = new Bundle();
bun.putString(“key”, “value”);
intent.putExtra(“key1”, bun);
接收:
Intent intent = getIntent();
Bundle bun = intent.getBundleExtra(“key1”);
String str = bun.getString(“key”);
5、参数回传
起始端:
a.Intent intent = new Intent(.this, .class);
b.startActivityForResult(intent, requestCode);
c.Override OnActivityResult(int requestCode, int resultCode, Intent data);
回调端:
a.Intent intent = getIntent();
b.Intent.put...
c.setResult(resultCode, intent);
d.Finish();
起始端设定requestCode标记被调用的Activity,回调端设定resultCode标记反馈位置,data为反馈的数据内容。