Use moveTaskToBack()
to move your app to the background.
To move it to the foreground, use the following code:
Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
startActivity(intent);
If you are trying to do this from a Service
or BroadcastReceiver
then you will need to do this before calling startActivity()
:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);