Example usage for android.content Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

List of usage examples for android.content Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

Introduction

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

Prototype

int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

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

Click Source Link

Document

If set, and this activity is either being started in a new task or bringing to the top an existing task, then it will be launched as the front door of the task.

Usage

From source file:com.sentaroh.android.SMBSync.NotificationUtil.java

@SuppressWarnings("deprecation")
static final public void initNotification(GlobalParameters gwa) {
    gwa.notificationManager = (NotificationManager) gwa.svcContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    gwa.notification = new Notification(R.drawable.ic_32_smbsync, gwa.svcContext.getString(R.string.app_name),
            0);//from  w  w  w .  j  a va  2 s  .co m

    gwa.notificationAppName = gwa.svcContext.getString(R.string.app_name);

    gwa.notificationIntent = new Intent(gwa.svcContext, SMBSyncMain.class);
    gwa.notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    gwa.notificationIntent.setAction(Intent.ACTION_MAIN);
    gwa.notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    gwa.notificationPendingIntent = PendingIntent.getActivity(gwa.svcContext, 0, gwa.notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    gwa.notificationBuilder = new NotificationCompat.Builder(gwa.svcContext);
    gwa.notificationBuilder.setContentIntent(gwa.notificationPendingIntent)
            //            .setTicker(gwa.notificationAppName)
            .setOngoing(true).setAutoCancel(false).setSmallIcon(gwa.notificationIcon)//smbsync_animation)
            .setContentTitle(gwa.notificationAppName).setContentText("")
            //          .setSubText("subtext")
            //          .setLargeIcon(largeIcon)
            .setWhen(0)
    //         .addAction(action_icon, action_title, action_pi)
    ;
    gwa.notification = gwa.notificationBuilder.build();
    if (Build.VERSION.SDK_INT >= 16) {//JB(4.1
        gwa.notificationBigTextStyle = new NotificationCompat.BigTextStyle(gwa.notificationBuilder);
        gwa.notificationBigTextStyle.setBigContentTitle(gwa.notificationLastShowedTitle)
                .bigText(gwa.notificationLastShowedMessage);
    }

}

From source file:com.sentaroh.android.TextFileBrowser.NotificationUtil.java

@SuppressWarnings("deprecation")
static final public void initNotification(Context c, NotificationCommonParms gwa) {
    gwa.notificationManager = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
    gwa.notification = new Notification(R.drawable.ic_32_browse_text, c.getString(R.string.app_name), 0);

    gwa.notificationAppName = c.getString(R.string.app_name);

    gwa.notificationIntent = new Intent(c, MainActivity.class);
    gwa.notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    gwa.notificationIntent.setAction(Intent.ACTION_MAIN);
    gwa.notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    gwa.notificationPendingIntent = PendingIntent.getActivity(c, 0, gwa.notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    buildNotification(c, gwa);//  w  ww . jav a  2  s  .c o m
}

From source file:com.sentaroh.android.SMBSync2.NotificationUtil.java

@SuppressWarnings("deprecation")
static final public void initNotification(GlobalParameters gwa) {
    gwa.notificationManager = (NotificationManager) gwa.appContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    gwa.notification = new Notification(R.drawable.ic_48_smbsync_wait,
            gwa.appContext.getString(R.string.app_name), 0);

    gwa.notificationAppName = gwa.appContext.getString(R.string.app_name);

    gwa.notificationIntent = new Intent(gwa.appContext, ActivityMain.class);
    gwa.notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    gwa.notificationIntent.setAction(Intent.ACTION_MAIN);
    gwa.notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    gwa.notificationPendingIntent = PendingIntent.getActivity(gwa.appContext, 0, gwa.notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    gwa.notificationLargeIcon = BitmapFactory.decodeResource(gwa.appContext.getResources(),
            gwa.notificationSmallIcon);//from  ww w  .  j a va 2  s .  com
    gwa.notificationBuilder = new NotificationCompat.Builder(gwa.appContext);
    gwa.notificationBuilder.setContentIntent(gwa.notificationPendingIntent)
            //            .setTicker(gwa.notificationAppName)
            .setOngoing(true).setAutoCancel(false).setSmallIcon(R.drawable.ic_48_smbsync_wait)//smbsync_animation)
            .setLargeIcon(gwa.notificationLargeIcon).setContentTitle(gwa.notificationAppName).setContentText("")
            //          .setSubText("subtext")
            //          .setLargeIcon(largeIcon)
            .setWhen(0)
    //         .addAction(action_icon, action_title, action_pi)
    ;
    gwa.notification = gwa.notificationBuilder.build();
    gwa.notificationBigTextStyle = new NotificationCompat.BigTextStyle(gwa.notificationBuilder);
    gwa.notificationBigTextStyle.setBigContentTitle(gwa.notificationLastShowedTitle)
            .bigText(gwa.notificationLastShowedMessage);

}

From source file:com.hsr.hemant.ppp.MainActivity.java

public static void openAppRating(Context context) {
    Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://dev?id=6565132919084735503"));
    boolean marketFound = false;

    // find all applications able to handle our rateIntent
    final List<ResolveInfo> otherApps = context.getPackageManager().queryIntentActivities(rateIntent, 0);
    for (ResolveInfo otherApp : otherApps) {
        // look for Google Play application
        if (otherApp.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {

            ActivityInfo otherAppActivity = otherApp.activityInfo;
            ComponentName componentName = new ComponentName(otherAppActivity.applicationInfo.packageName,
                    otherAppActivity.name);
            rateIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            rateIntent.setComponent(componentName);
            context.startActivity(rateIntent);
            marketFound = true;/*ww w.j a v  a  2s .c  om*/
            break;

        }
    }

    // if GP not present on device, open web browser
    if (!marketFound) {
        Intent webIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/dev?id=6565132919084735503"));
        context.startActivity(webIntent);
    }
}

From source file:hku.fyp14017.blencode.utils.StatusBarNotificationManager.java

public int createUploadNotification(Context context, String programName) {
    if (context == null || programName == null) {
        return -1;
    }//from   w  w w . jav a2 s . co m
    initNotificationManager(context);

    Intent uploadIntent = new Intent(context, MainMenuActivity.class);
    uploadIntent.setAction(Intent.ACTION_MAIN);
    uploadIntent = uploadIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, uploadIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationData data = new NotificationData(context, pendingIntent,
            hku.fyp14017.blencode.R.drawable.ic_stat, programName,
            hku.fyp14017.blencode.R.string.notification_upload_title_pending,
            hku.fyp14017.blencode.R.string.notification_upload_title_finished,
            hku.fyp14017.blencode.R.string.notification_upload_pending,
            hku.fyp14017.blencode.R.string.notification_upload_finished);

    int id = createNotification(context, data);
    showOrUpdateNotification(id, 0);
    return id;
}

From source file:com.android.leanlauncher.AppInfo.java

public static Intent makeLaunchIntent(Context context, LauncherActivityInfoCompat info, UserHandleCompat user) {
    long serialNumber = UserManagerCompat.getInstance(context).getSerialNumberForUser(user);
    return new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
            .setComponent(info.getComponentName())
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
            .putExtra(EXTRA_PROFILE, serialNumber);
}

From source file:org.catrobat.catroid.utils.StatusBarNotificationManager.java

public int createUploadNotification(Context context, String programName) {
    if (context == null || programName == null) {
        return -1;
    }//from w ww.  ja  v a  2 s  .c o m
    initNotificationManager(context);

    Intent uploadIntent = new Intent(context, MainMenuActivity.class);
    uploadIntent.setAction(Intent.ACTION_MAIN);
    uploadIntent = uploadIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, uploadIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationData data = new NotificationData(context, pendingIntent, R.drawable.ic_stat, programName,
            R.string.notification_upload_title_pending, R.string.notification_upload_title_finished,
            R.string.notification_upload_pending, R.string.notification_upload_finished);

    int id = createNotification(context, data);
    showOrUpdateNotification(id, 0);
    return id;
}

From source file:com.xabber.android.ui.activity.ContactList.java

public static Intent createPersistentIntent(Context context) {
    Intent intent = new Intent(context, ContactList.class);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}

From source file:mdn.vtvsport.GcmIntentService.java

private static void generateNotification(Context context, GCMInfo info) {
    /*//w  ww .j a va  2s. c o m
    int icon = R.drawable.icon_small;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
    .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, info.getMessage(),
    when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context,
    BaseSlideMenuActivity.class);
    notificationIntent.putExtra(GCMBUNDLE_ID, info.getItemId());
    notificationIntent.putExtra(GCMBUNDLE_TYPE, info.getType());
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0,
    notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, info.getMessage(),
    intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
    */

    String message = info.getMessage();
    Intent notificationIntent = new Intent(context, BaseSlideMenuActivity.class);
    notificationIntent.putExtra(GCMBUNDLE_ID, info.getItemId());
    notificationIntent.putExtra(GCMBUNDLE_TYPE, info.getType());
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);//FLAG_ACTIVITY_NEW_TASK

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(BaseSlideMenuActivity.class);
    stackBuilder.addNextIntent(notificationIntent);
    int id = -1;
    try {
        id = Integer.parseInt(info.getMessageId());
    } catch (Exception e) {
        // TODO: handle exception
    }
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(id, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setTicker(message)
            .setSmallIcon(R.drawable.icon_small).setContentTitle(HomeFragment.APP_NAME_1)
            .setContentText(message).setAutoCancel(true).setContentIntent(resultPendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle().setSummaryText(message));

    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(id, notification);
}

From source file:com.xabber.android.ui.activity.ContactListActivity.java

public static Intent createPersistentIntent(Context context) {
    Intent intent = new Intent(context, ContactListActivity.class);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}