Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to start Activity in background [duplicate]

Usually I start an activity with this code:

Intent i = new Intent(context, MyActivity.class);  
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);  

But how do I start the activity so that is left in the background?

like image 213
digitalfootmark Avatar asked Apr 17 '13 10:04

digitalfootmark


People also ask

How do I start the same activity again on android?

If you just want to reload the activity, for whatever reason, you can use this. recreate(); where this is the Activity. This is never a good practice. Instead you should startActivity() for the same activity and call finish() in the current one.

Can activity run in background android?

However, activity can't be run unless it's on foreground. In order to achieve what you want, in onPause(), you should start a service to continue the work in activity.

What does recreate () do Android?

When your activity is recreated after it was previously destroyed, you can recover your saved state from the Bundle that the system passes your activity. Both the onCreate() and onRestoreInstanceState() callback methods receive the same Bundle that contains the instance state information.


1 Answers

You should use Services for this - in addition the Class Description.

like image 80
M.Bennett Avatar answered Oct 22 '22 13:10

M.Bennett