Example usage for android.content Intent FLAG_ACTIVITY_NEW_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_NEW_TASK

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_NEW_TASK.

Prototype

int FLAG_ACTIVITY_NEW_TASK

To view the source code for android.content Intent FLAG_ACTIVITY_NEW_TASK.

Click Source Link

Document

If set, this activity will become the start of a new task on this history stack.

Usage

From source file:samples.piggate.com.piggateCompleteExample.Activity_Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize a Piggate object

    getSupportActionBar().setTitle("Piggate Offers Demo");

    networkErrorDialog = new AlertDialog.Builder(this).create();
    networkErrorDialog.setTitle("Network error");
    networkErrorDialog.setMessage("There is an error with the network connection");
    networkErrorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override//from w ww. ja va 2  s  .  c  om
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    setContentView(R.layout.activity_main);
    final Button login = (Button) findViewById(R.id.buttonloginmain);
    final Button register = (Button) findViewById(R.id.buttonregistermain);

    //onClick listener of the login button: go to Activity_SingIn
    login.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {

            Intent slideactivity = new Intent(Activity_Main.this, Activity_SingIn.class);
            slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            Bundle bndlanimation = ActivityOptions
                    .makeCustomAnimation(getApplicationContext(), R.anim.slidefromright, R.anim.slidetoleft)
                    .toBundle();
            startActivity(slideactivity, bndlanimation);
        }
    });

    //onClick listener of the register button: go to Activity_SingUp
    register.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {

            Intent slideactivity = new Intent(Activity_Main.this, Activity_SingUp.class);
            slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            Bundle bndlanimation = ActivityOptions
                    .makeCustomAnimation(getApplicationContext(), R.anim.slidefromright, R.anim.slidetoleft)
                    .toBundle();
            startActivity(slideactivity, bndlanimation);
        }
    });

    //If you close the application without logout, the session will be active
    //Call a listener of the RequestUser method for Piggate object
    if (Service_Notify.logout == false) {
        if (checkInternetConnection()) {

            loadingDialog = ProgressDialog.show(this, "Singing In", "Wait a few seconds", true);
            _piggate.RequestUser().setListenerRequest(new Piggate.PiggateCallBack() {
                //Method onComplete for JSONObject
                //If the request is completed correctly the user is redirected to Activity_Logged
                @Override
                public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {

                    loadingDialog.dismiss();
                    Intent slideactivity = new Intent(Activity_Main.this, Activity_Logged.class);
                    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                            R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                    startActivity(slideactivity, bndlanimation);
                }

                //Method onError for JSONObject
                //When we have an error, reload the Piggate object
                @Override
                public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                    loadingDialog.dismiss();
                    _piggate.reload();
                }

                //Method onComplete for JSONArray
                @Override
                public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                    //Unused
                }

                //Method onError for JSONArray
                @Override
                public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                    //Unused
                }
            }).exec();
        } else {
            networkErrorDialog.show();
        }
    }
}

From source file:com.geekandroid.sdk.sample.JPushReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();/*  ww w.j  a  v  a 2s . c  o  m*/
    Log.d(TAG, "[JPushReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));

    if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
        String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
        Log.d(TAG, "[JPushReceiver] Registration Id : " + regId);
        //send the Registration Id to your server...

    } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "[JPushReceiver] ???: "
                + bundle.getString(JPushInterface.EXTRA_MESSAGE));
        processCustomMessage(context, bundle);

    } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "[JPushReceiver] ??");
        int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
        Log.d(TAG, "[JPushReceiver] ??ID: " + notifactionId);

    } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
        Log.d(TAG, "[JPushReceiver] ");
        JPushImpl.getInstance().clearAllNotifications();

        //Activity
        Intent i = new Intent(context, JPushOpenActivity.class);
        i.putExtras(bundle);
        //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(i);

    } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
        Log.d(TAG, "[JPushReceiver] RICH PUSH CALLBACK: "
                + bundle.getString(JPushInterface.EXTRA_EXTRA));
        //? JPushInterface.EXTRA_EXTRA ??Activity ..

    } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
        boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
        Log.w(TAG, "[JPushReceiver]" + intent.getAction() + " connected state change to " + connected);
    } else {
        Log.d(TAG, "[JPushReceiver] Unhandled intent - " + intent.getAction());
    }
}

From source file:gov.nasa.arc.geocam.talk.UIUtils.java

/**
 * Go to the {@link GeoCamTalkLogon} activity.
 *
 * @param context The activity context to send the intent from.
 *///from  w  ww.  jav a 2s.  c  o m
public static void goToLogin(Context context) {
    final Intent intent = new Intent(context, GeoCamTalkLogon.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:im.delight.android.baselib.Social.java

/**
 * Constructs an Intent for sharing/sending a file and starts Activity chooser for that Intent
 *
 * @param context Context reference to start the Activity chooser from
 * @param windowTitle the string to be used as the window title for the Activity chooser
 * @param file the File instance to be shared
 * @param mimeType the MIME type for the file to be shared (e.g. image/jpeg)
 * @param messageTitle the message title/subject that may be provided in addition to the file, if supported by the target app
 *///from  w  ww. j  a  va  2 s . c o  m
public static void shareFile(Context context, String windowTitle, File file, final String mimeType,
        String messageTitle) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType(mimeType);
    intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    context.startActivity(Intent.createChooser(intent, windowTitle));
}

From source file:li.klass.fhem.appwidget.view.widget.medium.TargetStateWidgetView.java

@Override
protected void fillWidgetView(Context context, RemoteViews view, FhemDevice<?> device,
        WidgetConfiguration widgetConfiguration) {
    String payload = widgetConfiguration.payload.get(1);
    String state = device.getEventMapStateFor(payload);

    view.setTextViewText(R.id.button, state);

    PendingIntent pendingIntent;//www .  j a va 2  s  .c  om
    if (requiresAdditionalInformation(state)) {
        Intent actionIntent = new Intent(context, TargetStateAdditionalInformationActivity.class);
        actionIntent.putExtra(BundleExtraKeys.DEVICE_NAME, device.getName());
        actionIntent.putExtra(BundleExtraKeys.DEVICE_TARGET_STATE, payload);
        actionIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        pendingIntent = PendingIntent.getActivity(context, widgetConfiguration.widgetId, actionIntent,
                FLAG_UPDATE_CURRENT);
    } else {
        Intent actionIntent = new Intent(Actions.DEVICE_SET_STATE);
        actionIntent.setClass(context, DeviceIntentService.class);
        actionIntent.putExtra(BundleExtraKeys.DEVICE_NAME, device.getName());
        actionIntent.putExtra(BundleExtraKeys.DEVICE_TARGET_STATE, payload);

        pendingIntent = PendingIntent.getService(context, widgetConfiguration.widgetId, actionIntent,
                FLAG_UPDATE_CURRENT);
    }

    view.setOnClickPendingIntent(R.id.button, pendingIntent);

    openDeviceDetailPageWhenClicking(R.id.main, view, device, widgetConfiguration, context);
}

From source file:com.mono.applink.Twitter.java

/** Called when the activity is first created. */
@Override/*  w  w w  .  j  av a 2  s .  c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final String url = getIntent().getData().toString();

    if (url.contains("twitter.com") && !url.contains("status") && !url.contains("direct_messages")
            && !url.contains("user_spam_reports") && !url.contains("account") && !url.contains("settings"))//Just if it is a link of a user profile
    {
        new TwitterUser().execute();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Sorry, but this type of link is not currently supported");
        builder.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        builder.setPositiveButton("Open in Browser", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = new Intent();
                i.setAction("android.intent.action.VIEW");
                i.addCategory("android.intent.category.BROWSABLE");
                i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.setData(Uri.parse(url));
                startActivity(i);
                finish();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:com.codebutler.farebot.activities.MainActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);

    mDataCache = new HashMap<String, TransitIdentity>();

    registerForContextMenu(getListView());

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    Intent intent = new Intent(this, ReadingTagActivity.class);
    intent.addFlags(//w w w.  j av  a2  s  .c o m
            Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
    mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    mTechLists = new String[][] { new String[] { IsoDep.class.getName() },
            new String[] { MifareClassic.class.getName() }, new String[] { MifareUltralight.class.getName() },
            new String[] { NfcF.class.getName() } };

    setListAdapter(new CardsAdapter());
    getLoaderManager().initLoader(0, null, this);
}

From source file:co.uk.gauntface.mobile.devicelab.receiver.PushNotificationReceiver.java

private void launchBrowserTask(Context context, String url, String packageName) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    browserIntent.setPackage(packageName);
    browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    List<ResolveInfo> activitiesList = context.getPackageManager().queryIntentActivities(browserIntent, -1);
    if (activitiesList.size() > 0) {
        context.startActivity(browserIntent);
    } else {//from ww  w . j  a va 2  s  .c o m
        Intent playStoreIntent = new Intent(Intent.ACTION_VIEW);
        playStoreIntent.setData(Uri.parse("market://details?id=" + packageName));
        playStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(playStoreIntent);
    }
}

From source file:com.nextgis.maplibui.mapui.NGWVectorLayerUI.java

@Override
public void changeProperties(Context context) {
    Intent settings = new Intent(context, VectorLayerSettingsActivity.class);
    settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    settings.putExtra(ConstantsUI.KEY_LAYER_ID, getId());
    context.startActivity(settings);/*from w w w . j  av  a 2  s .c  o  m*/
}

From source file:im.delight.android.commons.Social.java

/**
 * Displays an application chooser and shares the specified file using the selected application
 *
 * @param context a context reference/*from  ww w  .  j a  v a  2 s . c o m*/
 * @param windowTitle the title for the application chooser's window
 * @param fileToShare the file to be shared
 * @param mimeTypeForFile the MIME type for the file to be shared (e.g. `image/jpeg`)
 * @param subjectTextToShare the message title or subject for the file, if supported by the target application
 */
public static void shareFile(final Context context, final String windowTitle, final File fileToShare,
        final String mimeTypeForFile, final String subjectTextToShare) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType(mimeTypeForFile);
    intent.putExtra(Intent.EXTRA_SUBJECT, subjectTextToShare);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileToShare));
    context.startActivity(Intent.createChooser(intent, windowTitle));
}