Show another Activity - Android android.app

Android examples for android.app:Activity Navigation

Description

Show another Activity

Demo Code

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;

public class Main{

    /** Show another Activity. */
    public static void show(@NonNull Context fromContext,
            @NonNull Class<? extends Activity> toActivity) {
        Intent intent = new Intent(fromContext, toActivity);
        if (!(fromContext instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }/*from w  w  w . ja  v a 2 s .c  o m*/
        fromContext.startActivity(intent);
    }

}

Related Tutorials