在IntentActivity中重写下列方法:onCreate onStart onRestart  onResume  onPause onStop onDestroy  onNewIntent

一、其他应用发Intent,执行下列方法:
I/@@@philn(12410): onCreate
I/@@@philn(12410): onStart
I/@@@philn(12410): onResume

发Intent的方法:

Uri uri = Uri.parse("philn://blog.163.com");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);

二、接收Intent声明: 

<activity android:name=".IntentActivity" android:launchMode="singleTask"
android:label="@string/testname">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="philn"/>
</intent-filter>
</activity>

三、如果IntentActivity处于任务栈的顶端,也就是说之前打开过的Activity,现在处于
I/@@@philn(12410): onPause
I/@@@philn(12410): onStop 状态的话
其他应用再发送Intent的话,执行顺序为:
I/@@@philn(12410): onNewIntent
I/@@@philn(12410): onRestart
I/@@@philn(12410): onStart
I/@@@philn(12410): onResume

在Android应用程序开发的时候,从一个Activity启动另一个Activity并传递一些数据到新的Activity上非常简单,但是当您需要让后台运行的Activity回到前台并传递一些数据可能就会存在一点点小问题。

首先,在默认情况下,当您通过Intent启到一个Activity的时候,就算已经存在一个相同的正在运行的Activity,系统都会创建一个新的Activity实例并显示出来。为了不让Activity实例化多次,我们需要通过在AndroidManifest.xml配置activity的加载方式(launchMode)以实现单任务模式,如下所示:

<activity android:label="@string/app_name" android:launchmode="singleTask"android:name="Activity1"></activity>

launchMode为singleTask的时候,通过Intent启到一个Activity,如果系统已经存在一个实例,系统就会将请求发送到这个实例上,但这个时候,系统就不会再调用通常情况下我们处理请求数据的onCreate方法,而是调用onNewIntent方法,如下所示:

 protected void onNewIntent(Intent intent) {

   super.onNewIntent(intent);

   setIntent(intent);//must store the new intent unless getIntent() will return the old one

   processExtraData();

 }

不要忘记,系统可能会随时杀掉后台运行的Activity,如果这一切发生,那么系统就会调用onCreate方法,而不调用onNewIntent方法,一个好的解决方法就是在onCreate和onNewIntent方法中调用同一个处理数据的方法,如下所示:

public void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);

   setContentView(R.layout.main);

   processExtraData();

 }

 protected void onNewIntent(Intent intent) {

   super.onNewIntent(intent);

   setIntent(intent);//must store the new intent unless getIntent() will return the old one

   processExtraData()

 }

 private void processExtraData(){

   Intent intent = getIntent();

   //use the data received here

 }

最新文章

  1. XidianOJ 1044 炸金花
  2. SQLServer清空数据库中所有的表并且ID自动归0
  3. redshift编译遇到的错误(ubuntu14.04)
  4. visio2007使用记录
  5. cassandra中对节点失败与否的探测方法, the Phi accrual Failure Dector,附论文
  6. 使用layout_weight设置控件占屏幕百分比
  7. Weka-学习
  8. bzoj 1602 [Usaco2008 Oct]牧场行走(LCA模板)
  9. 【Android】listview优化
  10. 第十二篇 C# 将HTML 直接转成Excel
  11. 阿里云负载均衡SLB的文件上传下载问题解决
  12. [Luogu P1354]房间最短路问题
  13. 用matplotlib.pyplot画简单的折线图,直方图,散点图
  14. Tomcat和Weblogic部署纯html文件
  15. C# GDI+之Graphics类 z
  16. 【NIFI】 Apache NiFI 之 ExecuteScript处理(二)
  17. 深入理解ASP.NET MVC(6)
  18. stage的划分
  19. 阿里云 rds python sdk不支持python3处理
  20. UsageGrideReport++

热门文章

  1. 15. 3Sum
  2. 网站不能访问(httperrLog【Timer_MinBytesPerSecond】【Timer_ConnectionIdle】)(转载)
  3. oracle锁机制
  4. JavaWeb学习记录(十九)——jstl自定义标签之简单标签
  5. spark共享变量
  6. (转)The 9 Deep Learning Papers You Need To Know About (Understanding CNNs Part 3)
  7. javaweb在线预览
  8. 谷歌大牛Jeff Dean是如何成为互联网战神的
  9. 非对称SVD电影推荐系统
  10. Android学习笔记进阶之在图片上涂鸦(能清屏)