Example usage for android.content Intent FLAG_ACTIVITY_TASK_ON_HOME

List of usage examples for android.content Intent FLAG_ACTIVITY_TASK_ON_HOME

Introduction

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

Prototype

int FLAG_ACTIVITY_TASK_ON_HOME

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

Click Source Link

Document

If set in an Intent passed to Context#startActivity Context.startActivity() , this flag will cause a newly launching task to be placed on top of the current home activity task (if there is one).

Usage

From source file:com.snappy.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from   www.  ja  v  a 2 s. co m
private void generateNotification(Context context, String message, String fromName, Bundle pushExtras,
        String body) {

    db = new LocalDB(context);
    List<LocalMessage> myMessages = db.getAllMessages();

    // Open a new activity called GCMMessageView
    Intent intento = new Intent(this, SplashScreenActivity.class);
    intento.replaceExtras(pushExtras);
    // Pass data to the new activity
    intento.putExtra(Const.PUSH_INTENT, true);
    intento.setAction(Long.toString(System.currentTimeMillis()));
    intento.addFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME);

    // Starts the activity on notification click
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the notification with a notification builder
    NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis())
            .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message))
            .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true)
            .setDefaults(
                    Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
            .setContentText(body).setContentIntent(pIntent);

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message));

    for (int i = 0; i < myMessages.size(); i++) {

        inboxStyle.addLine(myMessages.get(i).getMessage());
    }

    notification.setStyle(inboxStyle);

    // Remove the notification on click
    //notification.flags |= Notification.FLAG_AUTO_CANCEL;
    //notification.defaults |= Notification.DEFAULT_VIBRATE;
    //notification.defaults |= Notification.DEFAULT_SOUND;
    //notification.defaults |= Notification.DEFAULT_LIGHTS;

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.notify(R.string.app_name, notification.build());
    {
        // Wake Android Device when notification received
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

        final PowerManager.WakeLock mWakelock = pm
                .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH");
        mWakelock.acquire();
        // Timer before putting Android Device to sleep mode.
        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            public void run() {
                mWakelock.release();
            }
        };
        timer.schedule(task, 5000);
    }
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

private static void applyNewDocFlag(Intent i) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    } else {//from ww w.j  a v a  2s  .  c o m

        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
    }
}

From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java

/**
 * Method that opens the bookmarks activity.
 * @hide//  w  w  w .  j a  v  a2s  . com
 */
void openBookmarks() {
    Intent bookmarksIntent = new Intent(this, BookmarksActivity.class);
    bookmarksIntent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    startActivityForResult(bookmarksIntent, INTENT_REQUEST_BOOKMARK);
}

From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java

/**
 * Method that opens the history activity.
 * @hide/*www  .  ja  va 2 s.c om*/
 */
void openHistory() {
    Intent historyIntent = new Intent(this, HistoryActivity.class);
    historyIntent.putExtra(HistoryActivity.EXTRA_HISTORY_LIST, (Serializable) this.mHistory);
    historyIntent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    startActivityForResult(historyIntent, INTENT_REQUEST_HISTORY);
}

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * Carries out the "up" action in the action bar.
 *//*ww w .ja  v a2 s  . c  om*/
private void onAppUpPressed() {
    if (mLaunchedFromEmail) {
        // If this was started from Gmail, simply treat app up as the system back button, so
        // that the last view is restored.
        onBackPressed();
        return;
    }

    // Fire the main activity to ensure it launches the "top" screen of mail.
    // Since the main Activity is singleTask, it should revive that task if it was already
    // started.
    final Intent mailIntent = Utils.createViewInboxIntent(mAccount);
    mailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
            | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    startActivity(mailIntent);
    finish();
}