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.piggateInfoDemo.InfoActivity.java

public void backButton() {
    Intent slideactivity = new Intent(InfoActivity.this, Activity_Logged.class);
    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    Bundle bndlanimation = ActivityOptions
            .makeCustomAnimation(getApplicationContext(), R.anim.slidefromleft, R.anim.slidetoright).toBundle();
    startActivity(slideactivity, bndlanimation);
}

From source file:com.oakesville.mythling.MediaListActivity.java

protected void handleEmptyMediaList() {
    // go to main
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);/*from   ww w . ja v a  2 s .  c o m*/
    finish();
}

From source file:de.madvertise.android.sdk.MadvertiseAd.java

/**
 * Handles the click action (opens the click url)
 *//*www. j a v  a  2s.c o m*/
protected void handleClick() {
    if (mClickUrl != null && !mClickUrl.equals("")) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mClickUrl));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        try {
            mContext.startActivity(intent);
            if (mCallbackListener != null) {
                mCallbackListener.onAdClicked();
            }
        } catch (Exception e) {
            MadvertiseUtil.logMessage(null, Log.DEBUG, "Failed to open URL : " + mClickUrl);
            if (mCallbackListener != null) {
                mCallbackListener.onError(e);
            }
            e.printStackTrace();
        }
    }
}

From source file:com.rampgreen.caretakermobile.GcmIntentService.java

private void sendNotification(String notificationTitle, String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Bundle bundle = new Bundle();
    bundle.putString(Constants.NOTIFICATION_MSG, msg);
    bundle.putString(Constants.CALLED_COMPONENT, Constants.SERVICE_GCM_INTENT);

    Intent notificationIntent = new Intent(this, ActivityNotification.class);
    notificationIntent.putExtras(bundle);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(notificationTitle)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    Notification notification = mBuilder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(NOTIFICATION_ID, notification);
}

From source file:cm.aptoide.pt.DownloadQueueService.java

private void setNotification(int apkidHash, int progress) {

    String apkid = notifications.get(apkidHash).get("apkid");
    int size = Integer.parseInt(notifications.get(apkidHash).get("intSize"));
    String version = notifications.get(apkidHash).get("version");

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
    contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification);
    contentView.setTextViewText(R.id.download_notification_name,
            getString(R.string.download_alrt) + " " + apkid + " v." + version);
    contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, progress,
            false);/*  w  w  w. jav a  2 s .c  om*/

    Intent onClick = new Intent();
    onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt");
    onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    onClick.setAction("cm.aptoide.pt.FROM_NOTIFICATION");

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0);

    Notification notification = new Notification(R.drawable.ic_notification,
            getString(R.string.download_alrt) + " " + apkid, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = contentView;

    // Set the info for the notification panel.
    notification.contentIntent = onClickAction;
    //       notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Send the notification.
    // We use the position because it is a unique number.  We use it later to cancel.
    notificationManager.notify(apkidHash, notification);

    //      Log.d("Aptoide-DownloadQueueService", "Notification Set");
}

From source file:com.aqnote.app.wifianalyzer.MainActivity.java

private void reloadActivity() {
    finish();/*from   ww w.  ja  v a2 s . c om*/
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

From source file:com.gigathinking.simpleapplock.ResetUnlockMethod.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();/*  ww w  . j a  va  2s .c  o m*/
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.cvasilak.jboss.mobile.app.service.UploadToJBossServerService.java

@Override
protected void onHandleIntent(Intent intent) {
    // initialize

    // extract details
    Server server = intent.getParcelableExtra("server");
    String directory = intent.getStringExtra("directory");
    String filename = intent.getStringExtra("filename");

    // get the json parser from the application
    JsonParser jsonParser = new JsonParser();

    // start the ball rolling...
    final NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    builder.setTicker(String.format(getString(R.string.notif_ticker), filename))
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notif_large))
            .setSmallIcon(R.drawable.ic_stat_notif_small)
            .setContentTitle(String.format(getString(R.string.notif_title), filename))
            .setContentText(getString(R.string.notif_content_init))
            // to avoid NPE on android 2.x where content intent is required
            // set an empty content intent
            .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0)).setOngoing(true);

    // notify user that upload is starting
    mgr.notify(NOTIFICATION_ID, builder.build());

    // reset ticker for any subsequent notifications
    builder.setTicker(null);// w  ww .jav a 2s . co  m

    AbstractHttpClient client = CustomHTTPClient.getHttpClient();

    // enable digest authentication
    if (server.getUsername() != null && !server.getUsername().equals("")) {
        Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword());

        client.getCredentialsProvider().setCredentials(
                new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials);
    }

    final File file = new File(directory, filename);
    final long length = file.length();

    try {
        CustomMultiPartEntity multipart = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,
                new CustomMultiPartEntity.ProgressListener() {
                    @Override
                    public void transferred(long num) {
                        // calculate percentage

                        //System.out.println("transferred: " + num);

                        int progress = (int) ((num * 100) / length);

                        builder.setContentText(String.format(getString(R.string.notif_content), progress));

                        mgr.notify(NOTIFICATION_ID, builder.build());
                    }
                });

        multipart.addPart(file.getName(), new FileBody(file));

        HttpPost httpRequest = new HttpPost(server.getHostPort() + "/management/add-content");
        httpRequest.setEntity(multipart);

        HttpResponse serverResponse = client.execute(httpRequest);

        BasicResponseHandler handler = new BasicResponseHandler();
        JsonObject reply = jsonParser.parse(handler.handleResponse(serverResponse)).getAsJsonObject();

        if (!reply.has("outcome")) {
            throw new RuntimeException(getString(R.string.invalid_response));
        } else {
            // remove the 'upload in-progress' notification
            mgr.cancel(NOTIFICATION_ID);

            String outcome = reply.get("outcome").getAsString();

            if (outcome.equals("success")) {

                String BYTES_VALUE = reply.get("result").getAsJsonObject().get("BYTES_VALUE").getAsString();

                Intent resultIntent = new Intent(this, UploadCompletedActivity.class);
                // populate it
                resultIntent.putExtra("server", server);
                resultIntent.putExtra("BYTES_VALUE", BYTES_VALUE);
                resultIntent.putExtra("filename", filename);
                resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                // the notification id for the 'completed upload' notification
                // each completed upload will have a different id
                int notifCompletedID = (int) System.currentTimeMillis();

                builder.setContentTitle(getString(R.string.notif_title_uploaded))
                        .setContentText(String.format(getString(R.string.notif_content_uploaded), filename))
                        .setContentIntent(
                                // we set the (2nd param request code to completedID)
                                // see http://tinyurl.com/kkcedju
                                PendingIntent.getActivity(this, notifCompletedID, resultIntent,
                                        PendingIntent.FLAG_UPDATE_CURRENT))
                        .setAutoCancel(true).setOngoing(false);

                mgr.notify(notifCompletedID, builder.build());

            } else {
                JsonElement elem = reply.get("failure-description");

                if (elem.isJsonPrimitive()) {
                    throw new RuntimeException(elem.getAsString());
                } else if (elem.isJsonObject())
                    throw new RuntimeException(
                            elem.getAsJsonObject().get("domain-failure-description").getAsString());
            }
        }

    } catch (Exception e) {
        builder.setContentText(e.getMessage()).setAutoCancel(true).setOngoing(false);

        mgr.notify(NOTIFICATION_ID, builder.build());
    }
}

From source file:com.oakesville.mythling.MediaListActivity.java

public void refresh() {
    super.refresh();
    getAppSettings().setLastLoad(0);/*from ww w  . j a va  2s .  c  o  m*/
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    finish();
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.favorites.FavoritesPageTest.java

public void testAddToFavoriteFromDashboardView() {
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.ONLY_DASHBOARD);
    startActivityUnderTest();/*from   w  w  w .  ja  v a  2  s  . c o  m*/

    // Force only dashboards
    Intent intent = LibraryActivity_.intent(mApplication).flags(Intent.FLAG_ACTIVITY_NEW_TASK).get();
    getInstrumentation().startActivitySync(intent);
    getInstrumentation().waitForIdleSync();

    // Select dashboard
    onData(is(instanceOf(ResourceLookup.class))).inAdapterView(withId(android.R.id.list)).atPosition(1)
            .perform(click());

    // Add to favorite
    onView(withId(R.id.favoriteAction)).perform(click());
    pressBack();
    pressBack();

    onData(is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(click());

    // Remove from favorite
    onView(withId(R.id.favoriteAction)).perform(click());
    pressBack();
    onView(withId(android.R.id.list)).check(hasTotalCount(0));
    onView(withId(android.R.id.empty))
            .check(matches(allOf(withText(R.string.f_empty_list_msg), isDisplayed())));
}