简体   繁体   English

Android:同时进行两项活动

[英]Android: Two Activities Simultaneously

After searching for similar questions here on StackOverflow, I've come to the understanding that you cannot run 2 activities simultaneously. 在StackOverflow上搜索了类似的问题之后,我了解到您不能同时运行2个活动。 Is there any way around this? 有没有办法解决? I've read about Services and Asynctasks , but I'm still a little bit confused. 我已经阅读了有关ServicesAsynctasks ,但我仍然有些困惑。

I thought Threading/Intents/Handlers would work, but i'm finding that threading is a way to go from one activity to another (please correct me if I'm wrong) and not running two things at once. 我以为Threading/Intents/Handlers可以工作,但是我发现线程是一种从一种活动转到另一种活动的方法(如果我错了,请纠正我),而不是一次运行两件事。

Let's say I wanted to combine an android MediaPlayer activity and a video recording activity, while still being able to have the two interact with each other, would it be possible in android? 假设我想将android MediaPlayer活动和video recording活动结合起来,同时仍然能够使两者相互交互,那么在android中是否有可能? is it possible to have the camera running while having a video play/having a separate activity run within the same application? 是否可以在同一应用程序中同时播放视频或运行单独的活动的同时运行摄像机? If so, How? 如果是这样,如何?

I found a question here that addresses a similar issue( https://stackoverflow.com/questions/12021518/android-simultaneous-record-and-playback-different-sources ), But it is unanswered. 我在这里找到了一个解决类似问题的问题( https://stackoverflow.com/questions/12021518/android-simultaneous-record-and-playback-different-sources ),但此问题尚未得到解答。

Any suggestions or advice will be greatly appreciated! 任何建议或意见将不胜感激!

Intent , Handler and Thread are really 3 different things. IntentHandlerThread实际上是3种不同的东西。

An Intent is basically a message to say you did or want something to happen. Intent基本上是一条消息,表明您已完成或希望发生某些事情。 Depending on the intent, apps or the OS might be listening for it and will react accordingly. 根据意图,应用程序或操作系统可能正在监听它,并会做出相应的反应。 So an intend is used to navigate from one activity to another. 因此,意图用于从一个活动导航到另一个活动。 (For you example : A camera intent can be used a request to capture a picture or video clip through an existing camera app and then returns control back to your application.) (以您的示例为例:可以将摄像机意图用于通过现有摄像机应用程序捕获图片或视频剪辑的请求,然后将控制权返回给您的应用程序。)

A Thread must be created to execute long running jobs. 必须创建一个Thread才能执行长时间运行的作业。 If you do not explicitly start it in its own thread then it will run on the main (UI) thread which may be noticeable as jittery or slow to respond interface by your users. 如果未在其自己的线程中显式启动它,则它将在主(UI)线程上运行,这可能会引起用户的抖动或响应界面的响应缓慢。

A Handler is very convenient object to communicate between 2 threads (for instance : a background thread need to update the UI. You can use a Handler to post some Runnable from your background thread to the UI thread). Handler是在2个线程之间进行通信的非常方便的对象(例如:后台线程需要更新UI。您可以使用Handler将一些Runnable从后台线程发布到UI线程)。

As @krishna has mentioned you can try fragments... 正如@krishna提到的,您可以尝试片段...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM