温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android Activity怎么启动

发布时间:2021-12-18 16:34:55 来源:亿速云 阅读:135 作者:iii 栏目:移动开发

这篇文章主要介绍“Android  Activity怎么启动”,在日常操作中,相信很多人在Android  Activity怎么启动问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Android  Activity怎么启动”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

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

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

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

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

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

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

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

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

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

到此,关于“Android  Activity怎么启动”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI