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:de.lespace.apprtc.firebase.MyFirebaseMessagingService.java

/**
 * Called when message is received.//from  www  .j a  v a2s.c o  m
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    JSONObject jsonData = new JSONObject(remoteMessage.getData());
    Log.d(TAG, "calldata: " + jsonData.toString());

    Intent intent = new Intent(this, SignalingService.class);
    intent.putExtra(RTCConnection.EXTRA_SIGNALING_REGISTRATION, "true");
    intent.putExtra(RTCConnection.EXTRA_FROM, remoteMessage.getData().get("toUUID"));
    startService(intent);

    //Start Registration
    Log.d(TAG, "we should call to:" + remoteMessage.getData().get("fromUUID") + " but callto 'chrome' now!");
    Intent connectIntent = new Intent(getApplicationContext(), IncomingCall.class);
    String to = "chrome";
    RTCConnection.from = remoteMessage.getData().get("toUUID");
    RTCConnection.to = to;
    RTCConnection.initiator = true;
    /*
    connectIntent.putExtra(RTCConnection.EXTRA_TO, to);
    connectIntent.putExtra(RTCConnection.EXTRA_FROM, remoteMessage.getData().get("toUUID"));
    connectIntent.putExtra(RTCConnection.EXTRA_INITIATOR, true);*/
    connectIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(connectIntent);

}

From source file:de.grobox.blitzmail.SendActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // before doing anything show notification about sending process
    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setContentTitle(getString(R.string.sending_mail)).setContentText(getString(R.string.please_wait))
            .setSmallIcon(R.drawable.notification_icon).setOngoing(true);
    // Sets an activity indicator for an operation of indeterminate length
    mBuilder.setProgress(0, 0, true);/*from ww w . j av a 2s.com*/
    // Create Pending Intent
    notifyIntent = new Intent(this, NotificationHandlerActivity.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pendingIntent);
    // Issues the notification
    mNotifyManager.notify(0, mBuilder.build());

    Properties prefs;
    try {
        prefs = getPrefs();
    } catch (Exception e) {
        String msg = e.getMessage();

        Log.i("SendActivity", "ERROR: " + msg, e);

        if (e.getClass().getCanonicalName().equals("java.lang.RuntimeException") && e.getCause() != null
                && e.getCause().getClass().getCanonicalName().equals("javax.crypto.BadPaddingException")) {
            msg = getString(R.string.error_decrypt);
        }

        showError(msg);
        return;
    }

    // get and handle Intent
    Intent intent = getIntent();
    String action = intent.getAction();

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (action.equals(Intent.ACTION_SEND)) {
        String text = intent.getStringExtra(Intent.EXTRA_TEXT);
        //String email   = intent.getStringExtra(Intent.EXTRA_EMAIL);
        String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        String cc = intent.getStringExtra(Intent.EXTRA_CC);
        String bcc = intent.getStringExtra(Intent.EXTRA_BCC);

        // Check for empty content
        if (subject == null && text != null) {
            // cut all characters from subject after the 128th
            subject = text.substring(0, (text.length() < 128) ? text.length() : 128);
            // remove line breaks from subject
            subject = subject.replace("\n", " ").replace("\r", " ");
        } else if (subject != null && text == null) {
            text = subject;
        } else if (subject == null && text == null) {
            Log.e("Instant Mail", "Did not send mail, because subject and body empty.");
            showError(getString(R.string.error_no_body_no_subject));
            return;
        }

        // create JSON object with mail information
        mMail = new JSONObject();
        try {
            mMail.put("id", String.valueOf(new Date().getTime()));
            mMail.put("body", text);
            mMail.put("subject", subject);
            mMail.put("cc", cc);
            mMail.put("bcc", bcc);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        // remember mail for later
        MailStorage.saveMail(this, mMail);

        // pass mail on to notification dialog class
        notifyIntent.putExtra("mail", mMail.toString());

        // Start Mail Task
        AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail);
        mail.execute();
    } else if (action.equals("BlitzMailReSend")) {
        try {
            mMail = new JSONObject(intent.getStringExtra("mail"));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        // pass mail on to notification dialog class
        notifyIntent.putExtra("mail", mMail.toString());

        // Start Mail Task
        AsyncMailTask mail = new AsyncMailTask(this, prefs, mMail);
        mail.execute();
    }
    finish();
}

From source file:com.irontec.fragments.EzarpenakFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    setHasOptionsMenu(true);//  ww w.j a  v a2 s. c  om

    mContext = getActivity().getBaseContext();

    View rootView = inflater.inflate(R.layout.fragment_ezarpenak, container, false);
    mViewSwitcher = (ViewSwitcher) rootView.findViewById(R.id.viewSwitcher1);
    mEzarpenZerrenda = (ListView) rootView.findViewById(R.id.ezarpenak_list);

    mItems = new ArrayList<BasicNameValuePair>();

    BasicNameValuePair item1 = new BasicNameValuePair("Saioa itxi", "");
    BasicNameValuePair item2 = new BasicNameValuePair("Sare sozialak", "Zure sare sozialak kudeatu");
    BasicNameValuePair item3 = new BasicNameValuePair("Lizentziak", "Erabilitako baliabideak");
    BasicNameValuePair item4 = new BasicNameValuePair("Honi buruz", "");

    mItems.add(item1);
    mItems.add(item2);
    mItems.add(item3);
    mItems.add(item4);

    mEzarpenZerrenda.setAdapter(new SimpleLicenseAdapter(mContext, mItems));
    mEzarpenZerrenda.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
            Intent intent = null;
            if (position == 0) {
                MintzatuAPI.logout(mContext);
                intent = new Intent(getActivity().getBaseContext(), LoginCircles.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                if (getActivity() != null) {
                    getActivity().finish();
                }
            } else if (position == 3) {
                intent = new Intent(mContext, HoniBuruzActivity.class);
            } else {
                intent = new Intent(mContext, EzarpenakDetailActivity.class);
            }

            switch (position) {
            case 1:
                intent.putExtra("detail_type", 0);
                break;
            case 2:
                intent.putExtra("detail_type", 1);
                break;
            default:
                break;
            }

            if (intent != null) {
                startActivity(intent);
            }
        }
    });

    mViewSwitcher.showNext();

    return rootView;
}

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

/** Called when the activity is first created. */
@Override//from ww w.  ja  va 2  s  . c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    if (url.contains("user"))//user with id
    {
        new FoursquareUser().execute();
    } else if (url.contains("venue")) {
        new FoursquareVenue().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:at.wada811.dayscounter.CrashExceptionHandler.java

/**
 * ????????JSON?????/*from   www .  j  a  v  a 2  s.c  om*/
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
    // make Crash report
    CrashExceptionHandler.makeReportFile(mContext, throwable);
    // launch CrashReportActivity
    Intent intent = new Intent(mContext, CrashReportActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    mContext.startActivity(intent);
    //
    mHandler.uncaughtException(thread, throwable);
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callMayDeepLink(WebView webView, Uri uri) {
    boolean mayDeepLink;
    String cb = uri.getQueryParameter("cb");
    String urlParam = uri.getQueryParameter("url");

    if ((webView.getContext() == null) || (webView.getContext().getPackageManager() == null)
            || (urlParam == null)) {//from  ww w.j  av  a2  s  .c  om
        mayDeepLink = false;
    } else {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Uri.decode(urlParam)));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mayDeepLink = intent.resolveActivity(webView.getContext().getPackageManager()) != null;
    }

    LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
    list.add(new BasicNameValuePair(KEY_CALLER, CALL_MAYDEEPLINK));
    list.add(new BasicNameValuePair("mayDeepLink", String.valueOf(mayDeepLink)));
    loadResult(webView, cb, list);
}

From source file:com.thedamfr.facebook_dashclock_ext.ExampleExtension.java

@Override
protected void onUpdateData(int reason) {
    Session fbSession = Session.getActiveSession();
    if (fbSession == null) {
        Resources resources = this.getResources();
        AssetManager assetManager = resources.getAssets();
        Properties properties = new Properties();
        // Read from the /assets directory
        try {/*from  w ww  .  ja v a  2 s.co  m*/
            InputStream inputStream = assetManager.open("facebook.properties");
            properties.load(inputStream);
            System.out.println("The properties are now loaded");
            //System.out.println("properties: " + properties);
        } catch (IOException e) {
            System.err.println("Failed to open facebook property file");
            e.printStackTrace();
        }

        Session session = new Session.Builder(this).setApplicationId(properties.getProperty("app_id", ""))
                .build();
        Session.setActiveSession(session);
        fbSession = session;
    }
    if (fbSession != null && !fbSession.isOpened()) {
        Intent intent = new Intent(this, RefreshSessionActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
    if (fbSession.isOpened()) {
        Request notificationsRequest = Request.newGraphPathRequest(fbSession, "me/notifications",
                new Request.Callback() {

                    @Override
                    public void onCompleted(Response response) {
                        GraphObject object = response.getGraphObject();
                        if (object != null) {
                            JSONArray notifications = (JSONArray) object.getProperty("data");
                            if (notifications.length() >= 1) {
                                // Publish the extension data update.
                                String title = null;
                                String link = null;
                                try {
                                    title = ((JSONObject) notifications.get(0)).getString("title");
                                    link = ((JSONObject) notifications.get(0)).getString("link");
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                    title = "Can't read title";
                                }
                                publishUpdate(new ExtensionData().visible(true).icon(R.drawable.icon)
                                        .status("New Content")
                                        .expandedTitle(notifications.length() + "  notifications")
                                        .expandedBody(title)
                                        .clickIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(link))));

                            } else {
                                publishUpdate(new ExtensionData().visible(false).status("No Content"));
                            }
                        } else {
                            publishUpdate(new ExtensionData().visible(false).status("No Content"));
                        }

                    }
                });

        notificationsRequest.executeAsync();
    }

}

From source file:com.avanade.C2DMReceiver.java

@Override
public void onRegistrered(Context context, String registrationId) {
    Log.w("C2DMReceiver-onRegistered", registrationId);

    String urlString = "https://mobileapi.whatsnewat.com/WNADataService.svc/RegisterAndroidDevice?deviceToken='"
            + registrationId + "'&deviceID='" + LoginScreen.androidDevice_id + "'";
    HttpGet httpGet = new HttpGet(urlString);

    // set header parameters with user-provided credentials

    LoginScreen.httpFlag = 1;/*w  w  w . j ava  2 s  .  c  om*/
    HttpGetRequest token = new HttpGetRequest();
    httpGet.setHeader(Constants.emailId, LoginScreen.statEmailId);
    httpGet.setHeader(Constants.companyKey, LoginScreen.statCompKey);
    // obtain response XML from the server
    String xml = token.performGetRequest(httpGet);
    Intent dBUpdateIntent = new Intent(getBaseContext(), DatabaseUpdate.class);
    dBUpdateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    dBUpdateIntent.putExtra("DeviceId", registrationId);
    getApplication().startActivity(dBUpdateIntent);

    //      Intent dialogIntent = new Intent(getBaseContext(), NextPage.class);
    //      dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    //      getApplication().startActivity(dialogIntent);

}

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

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

    getSupportActionBar().setTitle("Piggate Info 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  w  w . j  a  v a 2s . c  o m*/
        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:io.selendroid.ServerInstrumentation.java

public void startActivity(Class activity) {
    if (activity == null) {
        SelendroidLogger.log("activity class is empty",
                new NullPointerException("Activity class to start is null."));
        return;//  w  w w . j  av  a  2 s.c om
    }
    finishAllActivities();
    // start now the new activity
    Intent intent = new Intent(getTargetContext(), activity);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    Activity a = startActivitySync(intent);
}