Snippets

Victor Apoyan How To: Bring Activity from Foreground Programatically

Created by Victor Apoyan
// this code will force the main activity to take focus as background for the chat window
//resolved issue- when a browser link is clicked browser does not take focus and
// launches in the background of main activity
PackageManager packageManager = mContext.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
if (intent != null) {
    intent.setPackage(null);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    mContext.startActivity(intent);
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.