Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TASK

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

Click Source Link

Document

If set in an Intent passed to Context#startActivity Context.startActivity() , this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.

Usage

From source file:org.liberty.android.fantastischmemo.downloader.quizlet.LoginQuizletActivity.java

public void onNewIntent(Intent intent) {
    //super.onNewIntent(intent);
    if (Intent.ACTION_VIEW.equals(intent.getAction()) && _dlg != null) {
        Uri uri = intent.getData();//  www .  jav a 2  s.  c om
        getDlg().processCallbackUrl(uri.toString());
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        //finish();
    }
}

From source file:com.turkiyedenemeleri.chronometer.ForegroundService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent.getAction().equals(Constants.ACTION.STARTFOREGROUND_ACTION)) {

        PrefUtils mPreferences = new PrefUtils(this);
        long wakeUpTime = (mPreferences.getStartedTime(intent.getStringExtra("snavid")) + 1800) * 1000;
        /*/*ww  w. ja v a 2 s.c o  m*/
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        Intent timerExpire = new Intent(this, TimerExpiredReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(this, 0, timerExpire, PendingIntent.FLAG_CANCEL_CURRENT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        am.setAlarmClock(new AlarmManager.AlarmClockInfo(wakeUpTime, sender), sender);
        } else {
        am.set(AlarmManager.RTC_WAKEUP, wakeUpTime, sender);
        }
        */
        Log.e("TAG", "4 bitince servisi durduracak, broadcast");

        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(Constants.ACTION.MAIN_ACTION);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        notificationIntent.putExtra("yeni", "yeni");
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        Log.e("TAG", "5 tklarsam ekran a");

        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

        Notification notification = new NotificationCompat.Builder(this).setContentTitle("Snav Devam Ediyor")
                .setTicker("Snav Devam Ediyor").setContentText("Snav Devam Ediyor")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingIntent)
                .setOngoing(true).build();

        startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, notification);
        Log.e("TAG", "6  Devam ediyor");

    } else if (intent.getAction().equals(Constants.ACTION.STOPFOREGROUND_ACTION)) {
        Log.i(LOG_TAG, "Received Stop Foreground Intent");

        Intent cancelIntent = new Intent(this, TimerExpiredReceiver.class);
        PendingIntent sender = PendingIntent.getBroadcast(this, 0, cancelIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        am.cancel(sender);
        Log.e("TAG", "9  Receiver pta");

        stopForeground(true);
        stopSelf();

        Log.e("TAG", "10 Notif ptal");
    }
    return START_REDELIVER_INTENT;
}

From source file:com.android.sandwichmaker.ui.NotifyService.java

private void issueNotification(Intent intent, String msg) {
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Bitmap bmp = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher);

    // Constructs the Builder object.
    builder = new NotificationCompat.Builder(this).setLargeIcon(bmp).setSmallIcon(R.drawable.ic_launcher)
            .setTicker(getString(R.string.hint)).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.notify_message)).setAutoCancel(true)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg));

    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra(CommonConstants.EXTRA_MESSAGE, msg);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    // Because clicking the notification opens a new ("special") activity, there's
    // no need to create an artificial back stack.
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(resultPendingIntent);
    startTimer(mMillis);/* w  ww  . ja va2s . c  o  m*/
}

From source file:com.example.ishita.administrativeapp.WatchmanSearchActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_logout) {

        personalData.SaveData(false);//w w w  .  j av  a2 s  .  c o  m
        Intent launch_logout = new Intent(WatchmanSearchActivity.this, MainActivity.class);
        launch_logout.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        launch_logout.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(launch_logout);
        finish();

    } /*else if(id==R.id.password) {
      Intent in = new Intent(getApplicationContext(), ChangePassword.class);
      startActivity(in);
              
      }*/
    return true;
}

From source file:mohammad.adib.oy.AccountActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account);
    setTransitionAnimations(R.anim.slide_in_top, R.anim.slide_out_bottom);
    mCurrentUser = ParseUser.getCurrentUser();
    //Set username and user motherland
    ((TextView) findViewById(R.id.username)).setText(mCurrentUser.getUsername().toUpperCase());
    ((ImageView) findViewById(R.id.icon)).setImageResource(getResources().getIdentifier(
            "flag_" + mCurrentUser.get(ParseConstants.KEY_MOTHERLAND).toString().toLowerCase(), "drawable",
            getPackageName()));// w ww. j a  va  2  s .  co m
    //Invite button
    findViewById(R.id.invite).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            OyUtils.sendInvite(AccountActivity.this);
        }
    });
    //Sign out
    findViewById(R.id.signout).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Unsubscribe from this user's notifications
            PushService.unsubscribe(AccountActivity.this, mCurrentUser.getUsername().toUpperCase());
            //Log user out
            mCurrentUser.logOut();
            //Take them to the intro
            Intent intent = new Intent(AccountActivity.this, IntroActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
        }
    });
    //Launch about activity
    findViewById(R.id.about).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            OyUtils.launchActivity(AccountActivity.this, AboutActivity.class, OyUtils.ANIM_ENTER,
                    OyUtils.ANIM_EXIT);
        }
    });
    //Done
    findViewById(R.id.done).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
            finish();
        }
    });
    updateOys();
}

From source file:at.wada811.dayscounter.CrashExceptionHandler.java

/**
 * ????????JSON?????/*  w  w w  . j a  va 2  s. com*/
 */
@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:budgetworld.ru.bw.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  w  w w .  j  a v  a 2s  .c  o m*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);

    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra("from notify", message);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("BudgetWorld")
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setLights(getResources().getColor(R.color.led), 2000, 2000);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

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/* w ww.ja va2s.c  om*/
        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:dentex.youtube.downloader.utils.Utils.java

public static void reload(Activity activity) {
    //finish/*from w w w .j ava2  s  . c  om*/
    activity.finish();
    activity.overridePendingTransition(0, 0);

    //start
    Intent intent = activity.getIntent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    activity.startActivity(intent);
    activity.overridePendingTransition(0, 0);
}

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

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

    getSupportActionBar().setTitle("Piggate Offers 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/*ww w .j a v a  2 s . 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();
        }
    }
}