Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have two activities running at the same time?

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.

like image 686
Michael Zeuner Avatar asked Jun 19 '12 13:06

Michael Zeuner


People also ask

Can 2 activities can be displayed 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.

Do more than one activity at the same time?

Human multitasking is the concept that one can split their attention on more than one task or activity at the same time, such as speaking on the phone while driving a car. Multitasking can result in time wasted due to human context switching and becoming prone to errors due to insufficient attention.

What is activity stack?

A task is a collection of activities that users interact with when trying to do something in your app. These activities are arranged in a stack—the back stack—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages.

What is Flag_activity_new_task?

When using this flag, if a task is already running for the activity you are now starting, then a new activity will not be started; instead, the current task will simply be brought to the front of the screen with the state it was last in. See FLAG_ACTIVITY_MULTIPLE_TASK for a flag to disable this behavior.


2 Answers

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.

like image 193
slayton Avatar answered Oct 17 '22 13:10

slayton


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.

like image 1
FoamyGuy Avatar answered Oct 17 '22 11:10

FoamyGuy