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:ch.bfh.instacircle.service.NetworkService.java

@Override
public void onDestroy() {

    // Stop everything if the leave message is coming from myself
    try {/*from  w  w w . j  av  a2  s.  c  om*/
        for (int i = 0; i < tcpUnicastReceiverThreads.length; i++) {
            tcpUnicastReceiverThreads[i].interrupt();
            udpBroadcastReceiverThreads[i].interrupt();
            tcpUnicastReceiverThreads[i].serverSocket.close();
            udpBroadcastReceiverThreads[i].socket.close();
        }
    } catch (Exception e) {

    }

    dbHelper.closeConversation();

    WifiManager wifiman = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    new AdhocWifiManager(wifiman).restoreWifiConfiguration(getBaseContext());
    WifiAPManager wifiAP = new WifiAPManager();
    if (wifiAP.isWifiAPEnabled(wifiman)) {
        wifiAP.disableHotspot(wifiman, getBaseContext());
    }
    stopSelf();
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    // Unregister the receiver which listens for messages to be sent
    LocalBroadcastManager.getInstance(this).unregisterReceiver(messageSendReceiver);

    // close the DB connection
    dbHelper.close();
    super.onDestroy();
}

From source file:com.farmerbb.taskbar.service.NotificationService.java

@TargetApi(Build.VERSION_CODES.M)
@Override//w  ww .j  ava2 s.c  o  m
public void onCreate() {
    super.onCreate();

    SharedPreferences pref = U.getSharedPreferences(this);
    if (pref.getBoolean("taskbar_active", false)) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this)) {
            isHidden = U.getSharedPreferences(this).getBoolean("is_hidden", false);
            String label = getString(isHidden ? R.string.action_show : R.string.action_hide);

            Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

            PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
            PendingIntent receiverIntent = PendingIntent.getBroadcast(this, 0,
                    new Intent("com.farmerbb.taskbar.SHOW_HIDE_TASKBAR"), PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent receiverIntent2 = PendingIntent.getBroadcast(this, 0,
                    new Intent("com.farmerbb.taskbar.QUIT"), PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(pref.getBoolean("app_drawer_icon", false) ? R.drawable.ic_system
                            : R.drawable.ic_allapps)
                    .setContentIntent(contentIntent).setContentTitle(getString(R.string.taskbar_is_active))
                    .setContentText(getString(R.string.click_to_open_settings))
                    .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
                    .addAction(0, label, receiverIntent)
                    .addAction(0, getString(R.string.action_quit), receiverIntent2)
                    .setPriority(Notification.PRIORITY_MIN).setShowWhen(false).setOngoing(true);

            startForeground(8675309, mBuilder.build());

            LocalBroadcastManager.getInstance(this)
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_SWITCH"));

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                TileService.requestListeningState(this, new ComponentName(BuildConfig.APPLICATION_ID,
                        QuickSettingsTileService.class.getName()));

            if (!isHidden) {
                registerReceiver(userForegroundReceiver, new IntentFilter(Intent.ACTION_USER_FOREGROUND));
                registerReceiver(userBackgroundReceiver, new IntentFilter(Intent.ACTION_USER_BACKGROUND));
            }
        } else {
            pref.edit().putBoolean("taskbar_active", false).apply();

            stopSelf();
        }
    } else
        stopSelf();
}

From source file:rnd.gw.plani.co.kr.groupware.GCM.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./* w ww.  jav  a 2 s  .c  o  m*/
 */

private void sendNotificationContact(String name, String title, String message, String link) {
    //        Intent[] intents = new Intent[2];
    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    //        intents[0] = intent;
    //        Intent i = new Intent(this, WebViewActivity.class);
    //        i.putExtra(WebViewActivity.EXTRA_CATEGORY,title);
    //        i.putExtra(WebViewActivity.EXTRA_URL,link);
    //        intents[1] = i;
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.launcher_icon_512);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setTicker(title)
            .setLargeIcon(icon).setSmallIcon(R.drawable.launcher_icon_512).setContentTitle(name)
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:id.satusatudua.sigap.ui.EscortActivity.java

@Override
public void onEscortFinished() {
    Intent intent = new Intent(this, TombolActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);/*from w  ww .  j av  a2s . c o  m*/
}

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

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

    if (getAppSettings().isFirstRun()) {
        new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(getString(R.string.setup_required))
                .setMessage(getString(R.string.access_network_settings))
                .setPositiveButton(getString(R.string.go_to_settings), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        startActivity(new Intent(MainActivity.this, PrefsActivity.class));
                    }/*from  w  w  w  .j  a v a  2s .  c om*/
                }).show();
    }

    setContentView(getAppSettings().isTv() ? R.layout.firetv_split : R.layout.split);

    findViewById(R.id.breadcrumbs).setVisibility(View.GONE);

    createProgressBar();

    backTo = getIntent().getStringExtra("back_to");

    setPathFromIntent();

    setSelItemIndex(getIntent().getIntExtra(SEL_ITEM_INDEX, 0));
    setTopOffset(getIntent().getIntExtra(TOP_OFFSET, 0));
    setCurrentTop(getIntent().getIntExtra(CURRENT_TOP, 0));

    String mode = getIntent().getStringExtra(MODE_SWITCH);
    modeSwitch = mode != null;
    if (mode == null)
        mode = getAppSettings().getMediaSettings().getViewType().toString();
    if (ViewType.list.toString().equals(mode))
        goListView();
    else if (ViewType.split.toString().equals(mode))
        goSplitView();

    if (getAppSettings().getMediaSettings().getViewType() == ViewType.detail) {
        Intent intent = new Intent(this, MediaPagerActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        if (backTo != null)
            intent.putExtra("back_to", backTo);
        startActivity(intent);
        finish();
        return;
    }

    listView = (ListView) findViewById(R.id.split_cats);

}

From source file:com.telepromptu.TeleprompterService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    Log.d(TAG, intent.toUri(0));/*  w w w  . j a v  a 2s .  co  m*/
    if (mLiveCard == null) {
        Log.d(TAG, "Publishing LiveCard");
        mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_TAG);

        // Keep track of the callback to remove it before unpublishing.
        mCallback = new TeleprompterDrawer(this);
        mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mCallback);

        Intent menuIntent = new Intent(this, MenuActivity.class);
        menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));

        mLiveCard.publish(PublishMode.REVEAL);
        Log.d(TAG, "Done publishing LiveCard");
    } else {
        // TODO(alainv): Jump to the LiveCard when API is available.
    }

    (new Thread(new Runnable() {

        @Override
        public void run() {
            //            String text = "Hi! My name is Waseem Ahmad! I'm a senior studying computer science at Rice University. Today, I'm going to demonstrate an application that my team has created called Telepromptu. It is a Google Glass application that serves as a live automatic teleprompter. The application uses speech recognition to get snippets of text from Google Speech recognition API. Because the speech to text recognition is not fully accurate, our application uses a local subsequence alignment algorithm to match the recognized text with text on the teleprompter.";
            slides = connect("http://telepromptu.appspot.com/glass?id=" + presentationId);
            String text = "";
            for (Slide slide : slides) {
                text += slide.notes + " ";
            }
            mCallback.mTeleprompterView.setText(text);
            speechTraverser = new SuperSpeechTraverser(text);
        }

    })).start();

    startListening();

    return START_STICKY;
}

From source file:org.hansel.myAlert.Registro.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.registro_layout);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    vUsuario = (EditText) findViewById(R.id.reg_fullname);
    vPassword = (EditText) findViewById(R.id.reg_password);
    vEmail = (EditText) findViewById(R.id.reg_email);
    errores = (TextView) findViewById(R.id.err_registro);
    Button btnCreate = (Button) findViewById(R.id.btnRegister);
    btnCreate.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            AttempCreate();//from  w  ww  .ja  va 2s. c  om
        }
    });
    Button btnCancelar = (Button) findViewById(R.id.btnCancelar);
    btnCancelar.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(Registro.this, Login.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (Util.isICS())
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            finish();
        }
    });
    usuarioDAO = new UsuarioDAO(this);
    usuarioDAO.open();
    mLoginFormView = findViewById(R.id.reg_form);
    mLoginStatusView = findViewById(R.id.reg_status);
    mLoginStatusMessageView = (TextView) findViewById(R.id.reg_status_message);

}

From source file:id.satusatudua.sigap.ui.RegisterActivity.java

@OnClick(R.id.login)
public void login() {
    Intent intent = new Intent(this, LoginActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);//from w w w  .  j  a va 2 s  .  c  o m
}

From source file:edu.stanford.mobisocial.dungbeetle.GroupsActivity.java

/*** Dashbaord stuff ***/
public void goHome(Context context) {
    final Intent intent = new Intent(context, HomeActivity.class);
    if (Build.VERSION.SDK_INT < 11)
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    else/*from  ww  w .j  a  v  a 2s .  co  m*/
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:edu.ucdenver.androidsecurity.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == SET_PASSWORD) {
        if (resultCode == RESULT_OK || resultCode == RESULT_FIRST_USER) {
            loadHomeScreen();//w  ww .j av  a 2s .co  m
        } else {
            Log.d("some error", "passcode failed!");
            adminPoliciesManager.removeAdminRights();
            Intent intent = new Intent(MainActivity.this, AdminRequestActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
        }
    }

    if (requestCode == DEVICE_ADMIN_REQUEST) {

        if (resultCode == RESULT_OK) {

            Long value = getIntent().getExtras().getLong("time1");
            System.out.println(value);
            //  long x= Long.parseLong(value);
            adminPoliciesManager.getmDPM().setMaximumTimeToLock(adminPoliciesManager.getmDeviceAdmin(), value);
            //The key argument here must match that used in the other activity

            // TODO: This should configurable by the user
            //                adminPoliciesManager.getmDPM().setMaximumFailedPasswordsForWipe(
            //                        adminPoliciesManager.getmDeviceAdmin(), 30);

            adminPoliciesManager.getmDPM().setPasswordQuality(adminPoliciesManager.getmDeviceAdmin(),
                    DevicePolicyManager.PASSWORD_QUALITY_COMPLEX);

            boolean isSufficient = adminPoliciesManager.getmDPM().isActivePasswordSufficient();

            if (isSufficient) {
                adminPoliciesManager.getmDPM().lockNow();

            } else {
                Intent setPasswordIntent = new Intent(

                        DevicePolicyManager.ACTION_SET_NEW_PASSWORD);

                startActivityForResult(setPasswordIntent, SET_PASSWORD);
                adminPoliciesManager.getmDPM()
                        .setPasswordExpirationTimeout(adminPoliciesManager.getmDeviceAdmin(), 864000000L);//864000000L

            }
            loadHomeScreen();
        }

        //loadHomeScreen();
        else {
            Intent intent = new Intent(MainActivity.this, AdminRequestActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);

            //                setContentView(R.layout.activity_enable_admin);
            //                    Button enabledAdminButton = (Button) findViewById(R.id.enabledAdminButton);
            //                enabledAdminButton.setOnClickListener(new View.OnClickListener() {
            //                        @Override
            //                        public void onClick(View view) {
            //                            loadAdminRequestScreen();
            //                        }
            //                });
        }
    }
}