Android应用程序组件Activity的"singleTask"(9)

这个函数中作用无非就是找到ID等于参数taskId的任务,然后在这个任务中查找是否已经存在即将要启动的activity的实例。

创新互联公司-专业网站定制、快速模板网站建设、高性价比苍溪网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式苍溪网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖苍溪地区。费用合理售后完善,十余年实体公司更值得信赖。

如果存在,就会把这 个Actvity实例上面直到任务堆栈顶端的Activity通过调用finishActivityLocked函数将它们结束掉。

在这个例子中,就是要 在属性值affinity等于"shy.luo.task"的任务中看看是否存在SubActivity类型的实例,如果有,就把它上面的 Activity都结束掉。

这里,属性值affinity等于"shy.luo.task"的任务只有一个MainActivity,而且它不是 SubActivity的实例,所以这个函数就返回null了。

回到前面的startActivityUncheckedLocked函数中,这里的变量top就为null了,于是执行下面的else语句:

 
 
  1. [java] view plaincopy if (top != null) { 
  2. ...... 
  3. } else { 
  4. // A special case: we need to 
  5. // start the activity because it is not currently 
  6. // running, and the caller has asked to clear the 
  7. // current task to have this activity at the top. 
  8. addingToTask = true; 
  9. // Now pretend like this activity is being started 
  10. // by the top of its task, so it is put in the 
  11. // right place. 
  12. sourceRecord = taskTop; 

于是,变量addingToTask值就为true了,同时将变量sourceRecord的值设置为taskTop,即前面调用findTaskLocked函数的返回值,这里,它就是表示MainActivity了。

继续往下看,下面这个if语句:

 
 
  1. [java] view plaincopy if (r.packageName != null) { 
  2. // If the activity being launched is the same as the one currently 
  3. // at the top, then we need to check if it should only be launched 
  4. // once. 
  5. ActivityRecord top = topRunningNonDelayedActivityLocked(notTop); 
  6. if (top != null && r.resultTo == null) { 
  7. if (top.realActivity.equals(r.realActivity)) { 
  8. if (top.app != null && top.app.thread != null) { 
  9. ...... 
  10. } else { 
  11. ...... 

网页标题:Android应用程序组件Activity的"singleTask"(9)
链接URL:http://www.hantingmc.com/qtweb/news18/255868.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联