两个页面交互的生命周期
antivity 生命周期
新年打卡,加油
匿名启动下Category属性不可缺
onSaveInstanceState通过Bundle保存需要保存的状态或者信息。
b activity的生命周期应该是oncreate->onstart->onResume吧,而不是onPause。
Activity启动方式
直接启动方式2种
Intent intent =new Intent(curActivity.this, newActivity.class);
startActivity(intent);
------------------------------------------------------------------
Intent intent =new Intent();
ComponentName componentName =new ComponentName(curActivity.this, newActivity.class);
intent.setComponent(componentName);
startActivity(intent);
匿名启动方式(针对打开其他APP的)
需要在Manifest.xml中注册新的Activity的标识,
<activity android:name=".newActivity">
<intent-filter>
<action android:name="www.imooc.com"/>
</intent-filter>
</activity>
返回类文件中,
Intent intent =new Intent();
intent.setAction("www.imooc.com");
startActivity(intent);
该方式可以说明可以通过自行定义的标识去调用一个Activity,但是,并未清楚的描述所谓的www.imooc.com这个标识可能来的途径。加入是其他APP,怎么知道这个标识?
Intent intent =new Intent();
打开系统浏览器
intent.setAction(Intent.ACTION_VIEW);
Uri url =Uri.parse("http://www.imooc.com");
intent.setData(url);
打开系统相册
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
//可以补充打开选择图片后,返回图片路径
打开系统短信
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "it's a msg");
打开系统电话
intent.setAction(Intent.ACTION_VIEW);
Uri url =Uri.parse("tel:123456");
intent.setData(url);
具体提供的系统ACTION功能,可以去开发文档中查找Intent类的解释会有介绍。
onDestroy()进行收尾释放资源。
Bundle用来存储Activity的数据,来进行传送。
横竖屏切换
竖.Create->竖.Start->竖.Resume【竖屏显示,点击切换横屏】
>>竖.Pause->竖.Stop->竖.Destroy【竖屏销毁,并开始创建横屏】
>>横.Create->横.Start->横.Resume【横屏显示】
1st.Pause后优先2nd.Create-2nd.Start-2nd.Resume是为了方式2nd创建时候,出现异常,导致画面异常。故把1st.Stop放到最后。
1st JUMPTO 2nd, 1st.Pause-2nd.Create-2nd.Start-2nd.Resume-1st.Stop <<<
2nd BACKTO 1st, 2nd.Pause-1st.Restart-1st.Start-1st.Resume-2nd.Stop-2nd.Destroy [back键会对上一个Activity进行销毁]<<<
Acitivity生命周期
1在mainActivity中加Button
新的Activity使用前要加到Apption

onCreate()->onStart()->onResume()->处于可见状态