Can you have two activities running at the same time?
Asked Answered
A

3

8

What I have is an activity with a severer, and another activity with different information on it. However when I open the non-sever activity the sever closes. Is there a way that I can get this to stop? If you need to see any code I would be happy to show it.

Anthropomorphic answered 19/6, 2012 at 13:46 Comment(1)
If one of the activities is in Picture-In-Picture mode then yes.Jacobi
M
13

You cannot have multiple activities running at the same time. If you want code to run in the background you need to use a Service. For more information checkout the docs: http://developer.android.com/reference/android/app/Service.html

You should program your server as a Service and then write an Activity that communicates with the server and displays relevant information. This way when you navigate to a new Activity the server continues to run.

Metaphysical answered 19/6, 2012 at 13:48 Comment(1)
This answer is wrong since Android 7. In Multi-Window mode which is now the default you can show it and an Activity is now almost just the same as a Window is in any GUI Desktop system.Splayfoot
S
1

Can you have two activity's running at the same time

Not in the sense that you are expecting. In Android Activities are stored on a stack, only the top one on the stack is shown on the screen. While the other activities that aren't at the top are not necessarily all the way "dead" they are not alive enough to do that work for you.

You should instead make your server into a Service.

Stanfield answered 19/6, 2012 at 13:49 Comment(1)
I was wondering if you could look at this question and see if you can help me here, because I think that way is how I truly want it. #11076492Anthropomorphic
S
0

you can try multi-window, perhaps not your expected: https://developer.android.com/guide/topics/ui/multi-window

Spaceport answered 15/6, 2021 at 8:51 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. link-only-answersBennion

© 2022 - 2025 — McMap. All rights reserved.