1

After searching for similar questions here on StackOverflow, I've come to the understanding that you cannot run 2 activities simultaneously. Is there any way around this? I've read about Services and Asynctasks, but I'm still a little bit confused.

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.

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? 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.

Any suggestions or advice will be greatly appreciated!

Community
  • 1
  • 1
Bethany
  • 63
  • 3
  • 11
  • 3
    You can try [Fragments](http://developer.android.com/guide/components/fragments.html) – Krrishnaaaa Jul 10 '13 at 04:58
  • 1
    Intents is used to go from one Activity to other – Nargis Jul 10 '13 at 05:10
  • 2
    Fragments could help, if its not necessary to have two diff activities then probably you can use them both in the same activity? – Adnan Mulla Jul 10 '13 at 05:13
  • thank you for the comments! @Krrishnaaaa I read a bit about fragments- it seems like it means i would have to split the screen for the two activities. ideally i would like to overlay the MediaPlayer on top of the video recording preview while having both run simultaneously, but that seems far-reaching as of now.. will definitely look into it though! – Bethany Jul 10 '13 at 05:48
  • @AdnanMulla do you know by any chance if i can have the android camera running and a mediaplayer playing in the same activity? i'm assuming not because both require the screen(video player screen and camera preview screen) though I wonder... – Bethany Jul 10 '13 at 05:48
  • @Bethany: did you manage to find any help in this regard? – صلي علي محمد - Atef Farouk Dec 12 '21 at 07:32

1 Answers1

2

Intent ,Handler and Thread are really 3 different things.

An Intent is basically a message to say you did or want something to happen. 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. 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.

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).

As @krishna has mentioned you can try fragments...

Ameer Moaaviah
  • 1,530
  • 12
  • 27
  • thank you for the clear explanation! i do know that starting long running jobs in the ui thread would slow everything down, but i guess i'm actually confused about the difference between an activity and a thread. i thought activities were essentially like threads-and hence i tried to combine two activities like threads and ran into some trouble. i had thought that making another activity= starting a long running job on a non-UI thread. anyways, i'll look more into fragments. thanks again! – Bethany Jul 10 '13 at 06:00