活动的生命周期创建,启动和运行过程 [英] Activity life cycle creating,starting and running procedure

查看:171
本文介绍了活动的生命周期创建,启动和运行过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的第一个活动是只是一个形象,我的第二个活动是一首歌曲,一个计算器。所以,如果我开始我的第二个活动,然后我把我的第一次活动睡眠5000毫秒,然后杀死它......会发出声音,而我的第一个活动的形象出现在屏幕上会玩吗?并在会在睡眠期间,我的计算器?

If my first activity is just an image, and my second activity is a song and a calculator. So If I start my second activity and then I make a sleep on my first activity for 5000ms and then kill it... will sound will play while my first activity's image is on the screen? And where will be my calculator during sleep period ?

推荐答案

没有。如果休眠你的第一个活动,假设你正在谈论的 UI 线程,而不是一个后台线程,然后你的整个 UI 会睡眠到时候...这意味着你的第二个活动不会还没有开始,你的歌曲将无法播放。

No. If you "sleep" your first Activity, assuming you are talking about the UI thread and not a background thread, then your whole UI will sleep for that time...meaning your second Activity won't be started yet and your song won't play.

你可以做的是把它们都放在一个活动并把你的形象和计算器在同一位置,或任何你想要的布局,并隐藏计算器从你的XML开头以

What you could do is put it all in one Activity and put your image and calculator in the same position, or wherever you want in the layout, and hide your calculator from the beginning in your xml with

 android:visibility="invisible" // or gone depending on what you need

然后当你有需要你可以改变这两种观点的知名度。我不知道你想要的,所以我不知道到底是什么,如果这个解决方案是合适的。

Then you can change the visibility of both views when you need. I don't know exactly what you want so I don't know if this solution is suitable.

您也可以考虑把你的歌在服务

You also could look into putting your song in a Service

这篇关于活动的生命周期创建,启动和运行过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆