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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_connect);
    // Get setting keys.
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    missingPermissions = new ArrayList();

    for (String permission : MANDATORY_PERMISSIONS) {
        if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
            missingPermissions.add(permission);
        }//from ww  w. ja  v  a2 s . c om
    }
    requestPermission();

    //Bring Call2Front when
    bringToFrontBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            Intent intentStart = new Intent(getApplicationContext(), ConnectChatActivity.class);
            // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
            startActivity(intentStart);
            //  newFragment.show(transaction,"loading");

            //  showDialog();
        }
    };

    registerBringToFrontReceiver();

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }

    ImageButton connectButton = (ImageButton) findViewById(R.id.connect_button);
    connectButton.setOnClickListener(connectListener);

    // If an implicit VIEW intent is launching the app, go directly to that URL.
    //final Intent intent = getIntent();
    Uri wsurl = Uri.parse(Configs.ROOM_URL);
    //intent.getData();
    Log.d(TAG, "connecting to:" + wsurl.toString());
    if (wsurl == null) {
        logAndToast(getString(R.string.missing_wsurl));
        Log.e(TAG, "Didn't get any URL in intent!");
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    if (from == null || from.length() == 0) {
        logAndToast(getString(R.string.missing_from));
        Log.e(TAG, "Incorrect from in intent!");
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    roomConnectionParameters = new AppRTCClient.RoomConnectionParameters(wsurl.toString(), from, false);

    Log.i(TAG, "creating appRtcClient with roomUri:" + wsurl.toString() + " from:" + from);
    // Create connection client and connection parameters.
    appRtcClient = new WebSocketRTCClient(this, new LooperExecutor());

    connectToWebsocket();
    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
}

From source file:com.linkbubble.MainApplication.java

private void showNewBraveBrowserHiddenNotification() {
    Intent resultIntent = new Intent(this, NotificationNewBraveBrowserActivity.class);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat)
            .setContentTitle(getResources().getString(R.string.tab_based_browser_notification_title))
            .setContentText(getResources().getString(R.string.tab_based_browser_notification_text))
            .setAutoCancel(true).setContentIntent(resultPendingIntent);

    // Gets an instance of the NotificationManager service
    NotificationManager notifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
    notifyMgr.notify(NotificationNewBraveBrowserActivity.NOTIFICATION_ID, builder.build());
}

From source file:com.magnet.mmx.client.MMXWakeupIntentService.java

private void invokeNotificationForPush(GCMPayload payload) {
    // Launch the activity with action=MAIN, category=DEFAULT.  Make sure that
    // it has DEFAULT category declared in AndroidManifest.xml intent-filter.
    PendingIntent intent = PendingIntent.getActivity(this.getApplicationContext(), 0,
            new Intent(Intent.ACTION_MAIN).setPackage(this.getPackageName())
                    .addCategory(Intent.CATEGORY_DEFAULT) // it is redundant
                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    .addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED),
            PendingIntent.FLAG_UPDATE_CURRENT);
    // If title is not specified, use the app name (compatible with iOS push notification)
    String title = (payload.getTitle() == null) ? this.getApplicationInfo().name : payload.getTitle();
    Notification.Builder noteBuilder = new Notification.Builder(this).setContentIntent(intent)
            .setAutoCancel(true).setWhen(System.currentTimeMillis()).setContentTitle(title)
            .setContentText(payload.getBody());
    if (payload.getSound() != null) {
        // TODO: cannot handle custom sound yet; use notification ring tone.
        noteBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    }//from  w  w  w.  j  a v  a2s  . c  o  m
    if (payload.getIcon() != null) {
        noteBuilder.setSmallIcon(
                this.getResources().getIdentifier(payload.getIcon(), "drawable", this.getPackageName()));
    } else {
        noteBuilder.setSmallIcon(this.getApplicationInfo().icon);
    }
    if (payload.getBadge() != null) {
        noteBuilder.setNumber(payload.getBadge());
    }
    NotificationManager noteMgr = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    noteMgr.notify(sNoteId++, noteBuilder.build());
}

From source file:edu.mit.mobile.android.demomode.DemoMode.java

/**
 * Loads the list of installed applications in mApplications.
 *//*from w w  w  .j  a  va  2  s.co  m*/
private void loadApplications(boolean isLaunching) {
    if (isLaunching && mApplications != null) {
        return;
    }

    final PackageManager manager = getPackageManager();

    final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
    Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));

    if (apps != null) {
        final int count = apps.size();

        if (mApplications == null) {
            mApplications = new ArrayList<ApplicationInfo>(count);
        }
        mApplications.clear();

        for (int i = 0; i < count; i++) {
            final ApplicationInfo application = new ApplicationInfo();
            final ResolveInfo info = apps.get(i);

            application.title = info.loadLabel(manager);
            application.setActivity(
                    new ComponentName(info.activityInfo.applicationInfo.packageName, info.activityInfo.name),
                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            application.icon = info.activityInfo.loadIcon(manager);

            mApplications.add(application);
        }
    }
}

From source file:codepath.watsiapp.utils.Util.java

private static void startShareIntentWithExplicitSocialActivity(Activity ctx, ShareableItem patient,
        Set<String> socialActivitiesName, String displayName) {
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, patient.getShareableUrl());

    try {//from w  ww .j a  v  a  2  s .  c  o  m
        final PackageManager pm = ctx.getPackageManager();
        final List activityList = pm.queryIntentActivities(shareIntent, 0);
        int len = activityList.size();
        for (int i = 0; i < len; i++) {
            final ResolveInfo app = (ResolveInfo) activityList.get(i);
            Log.d("#####################", app.activityInfo.name);
            if (socialActivitiesName.contains(app.activityInfo.name)) {
                final ActivityInfo activity = app.activityInfo;
                final ComponentName name = new ComponentName(activity.applicationInfo.packageName,
                        activity.name);
                shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Fund Treatment");
                shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                shareIntent.setComponent(name);
                ctx.startActivity(shareIntent);
                break;
            }
        }
    } catch (final ActivityNotFoundException e) {
        Toast.makeText(ctx, "Could not find " + displayName + " app", Toast.LENGTH_SHORT).show();
    }

}

From source file:com.gigaset.home.Home.java

/**
 * Loads the list of installed applications in mApplications.
 *//*from w w  w .  j  a v  a 2s. com*/
private void loadApplications(boolean isLaunching) {

    if (isLaunching && mApplications != null) {
        return;
    }

    PackageManager manager = getPackageManager();

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
    Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));

    if (apps != null) {
        final int count = apps.size();

        if (mApplications == null) {
            mApplications = new ArrayList<ApplicationInfo>(count);
        }
        mApplications.clear();

        ApplicationInfo application;
        // ********************* ADD Key Pad **********************************
        application = new ApplicationInfo();
        application.title = "Key Pad";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_iocon_key_pad);
        application.setActivity(
                new ComponentName("com.android.contacts", "com.android.contacts.activities.DialtactsActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Messages *********************************
        application = new ApplicationInfo();
        application.title = "Messages";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_icon_messages);
        application.setActivity(new ComponentName("com.android.mms", "com.android.mms.ui.ConversationList"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Contacts *********************************
        application = new ApplicationInfo();
        application.title = "Contacts";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_icon_contacts);
        application.setActivity(
                new ComponentName("com.android.contacts", "com.android.contacts.activities.PeopleActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Call Log *********************************
        // http://hi-android.info/src/index.html            
        application = new ApplicationInfo();
        application.title = "Call List";
        application.icon = getResources().getDrawable(R.drawable.main_screen_icon_call_log);

        application.setActivityWithAction(Intent.ACTION_VIEW, CallLog.Calls.CONTENT_TYPE);
        mApplications.add(application);

        // ********************* ADD Browser **********************************
        application = new ApplicationInfo();
        application.title = "Browser";
        application.icon = application.icon = getResources().getDrawable(R.drawable.main_screen_icon_browser);
        application.setActivity(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        // ********************* ADD Call Settings ****************************
        application = new ApplicationInfo();
        application.title = "Call Settings";
        application.icon = application.icon = getResources()
                .getDrawable(R.drawable.main_screen_icon_call_settings);
        application.setActivity(new ComponentName("com.android.settings", "com.android.settings.Settings"),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mApplications.add(application);

        //            
        //            for (int i = 0; i < count; i++) 
        //            {
        //                ApplicationInfo application = new ApplicationInfo();
        //                ResolveInfo info = apps.get(i);
        //
        //                application.title = info.loadLabel(manager);
        //                application.setActivity(new ComponentName(
        //                        info.activityInfo.applicationInfo.packageName,
        //                        info.activityInfo.name),
        //                        Intent.FLAG_ACTIVITY_NEW_TASK
        //                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        //                
        //                Log.v("Home APP", "package neme= "+info.activityInfo.applicationInfo.packageName);
        //                Log.v("Home APP", "neme= "+info.activityInfo.name);
        //                Log.v("Home APP", "title= "+application.title);
        //                
        //                
        //                application.icon = info.activityInfo.loadIcon(manager);
        //                
        //                // Replace Icons
        //                if((application.title+"").equals("Browser"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_browser);
        //                if((application.title+"").equals("Phone"))       application.icon = getResources().getDrawable(R.drawable.main_screen_iocon_key_pad);
        //                if((application.title+"").equals("People"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_contacts);
        //                if((application.title+"").equals("Messaging"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_messages);
        //                if((application.title+"").equals("Settings"))    application.icon = getResources().getDrawable(R.drawable.main_screen_icon_call_settings);
        //                //if((application.title+"").equals("Call Log")) application.icon = getResources().getDrawable(R.drawable.main_screen_icon_call_log);
        //                
        //                // Add Application
        //                if((application.title+"").equals("Browser"))    mApplications.add(application);
        //                if((application.title+"").equals("Phone"))       mApplications.add(application);
        //                if((application.title+"").equals("People"))    mApplications.add(application);
        //                if((application.title+"").equals("Messaging"))    mApplications.add(application);
        //                if((application.title+"").equals("Settings"))    mApplications.add(application);
        //
        //            }

    }
}

From source file:com.example.demo_highlights.slidingmenu.activity.SlidingActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub

    switch (item.getItemId()) {
    case R.id.menu1:

        Intent intent = new Intent("android.provider.Telephony.SECRET_CODE",
                Uri.parse("android_secret_code://" + "4636"));
        sendBroadcast(intent);//from   w w  w . j  av a  2  s  .c  o m

        return true;
    case R.id.menu2:
        return true;
    case R.id.menu3:
        return true;
    case R.id.menu4:
        return true;
    case R.id.menu5:
        final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
        settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        startActivity(settings);
        return true;
    case R.id.menu6:
        final Intent demo_settings = new Intent(SlidingActivity.this, DemoSettingActivity.class);
        startActivity(demo_settings);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * Home//from w  w  w  .  ja  va2  s.  c o m
 * @param context
 */
public static void goHome(Context context) {
    Intent mHomeIntent = new Intent(Intent.ACTION_MAIN);
    mHomeIntent.addCategory(Intent.CATEGORY_HOME);
    mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(mHomeIntent);
}

From source file:org.bohrmeista.chan.ui.service.WatchNotifier.java

@SuppressWarnings("deprecation")
private Notification getNotificationFor(String tickerText, String title, String content, int count,
        List<CharSequence> lines, boolean makeSound, Pin targetPin) {

    Intent intent = new Intent(this, BoardActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    intent.putExtra("pin_id", targetPin == null ? -1 : targetPin.id);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentIntent(pendingIntent);

    if (tickerText != null) {
        tickerText = tickerText.substring(0, Math.min(tickerText.length(), 50));
    }//from  w w  w .  j a  v a 2 s.  c om

    builder.setTicker(tickerText);
    builder.setContentTitle(title);
    builder.setContentText(content);

    if (count >= 0) {
        builder.setContentInfo(Integer.toString(count));
        builder.setNumber(count);
    }

    builder.setSmallIcon(R.drawable.ic_stat_notify);

    Intent pauseWatching = new Intent(this, WatchNotifier.class);
    pauseWatching.putExtra("pause_pins", true);

    PendingIntent pauseWatchingPending = PendingIntent.getService(this, 0, pauseWatching,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.addAction(R.drawable.ic_action_pause, getString(R.string.watch_pause_pins), pauseWatchingPending);

    if (makeSound) {
        builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    }

    if (lines != null) {
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
        for (CharSequence line : lines.subList(Math.max(0, lines.size() - 10), lines.size())) {
            style.addLine(line);
        }
        style.setBigContentTitle(title);
        builder.setStyle(style);
    }

    return builder.getNotification();
}

From source file:com.linkbubble.MainService.java

private void showDefaultNotification() {
    Intent closeAllIntent = new Intent(this, NotificationCloseAllActivity.class);
    closeAllIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent closeAllPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
            closeAllIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    /*Intent showContentViewIntent = new Intent(this, NotificationShowContentActivity.class);
    showContentViewIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent showContentViewPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), showContentViewIntent, PendingIntent.FLAG_UPDATE_CURRENT);*/

    Intent hideIntent = new Intent(this, NotificationHideActivity.class);
    hideIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent hidePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
            hideIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat).setPriority(Notification.PRIORITY_MIN)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.notification_default_summary))
            //.addAction(R.drawable.ic_action_eye_closed_dark, getString(R.string.notification_action_hide), hidePendingIntent)
            //.addAction(R.drawable.ic_action_cancel_dark, getString(R.string.notification_action_close_all), closeAllPendingIntent)
            .addAction(/* www . ja  v a2 s .co m*/
                    Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ? R.drawable.ic_action_cancel_white
                            : R.drawable.ic_action_cancel_dark,
                    getString(R.string.notification_action_close_all), closeAllPendingIntent)
            //.addAction(Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ? R.drawable.ic_action_cancel_white : R.drawable.ic_action_cancel_dark, getString(R.string.notification_expand), showContentViewPendingIntent)
            .setGroup(Constant.NOTIFICATION_GROUP_KEY_ARTICLES).setGroupSummary(true).setLocalOnly(true)
            .setContentIntent(hidePendingIntent);

    /*MainController controller = MainController.get();
    if (null != controller && null != controller.mBubbleFlowDraggable) {
    if (!controller.mBubbleFlowDraggable.isExpanded()) {
        notificationBuilder
                .addAction(R.drawable.ic_stat, getString(R.string.notification_expand), showContentViewPendingIntent)
                .setContentText(getString(R.string.notification_default_expand_summary));
    }
    }*/

    // Nuke all previous notifications and generate unique ids
    NotificationManagerCompat.from(this).cancelAll();
    int notificationId = 77;

    startForeground(notificationId, notificationBuilder.build());
}