Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TOP

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

Click Source Link

Document

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

Usage

From source file:notused.Login.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);//from   w ww  .  j  a  v  a 2  s  . c o  m

    txtEmail = (TextView) findViewById(R.id.email);
    txtPassword = (TextView) findViewById(R.id.password);
    btnLogin = (Button) findViewById(R.id.login);
    ckRememberMe = (CheckBox) findViewById(R.id.checkbox);
    txtForgotPassword = (TextView) findViewById(R.id.forgotPassword);
    txtSignUp = (TextView) findViewById(R.id.signUp);
    validator = new Validator();
    config = new Config(Login.this);
    dbAdapter = new UserDBAdapter(this);

    baseUrl = "http://lawpavilionstore.com/android/login";

    dbAdapter.open(DB_NAME);
    //TODO: remove drop table query
    dbAdapter.executeQuery("DROP TABLE IF EXISTS" + dbAdapter.TABLE_NAME + ";");
    //dbAdapter.createUserTable();

    Cursor cursor = dbAdapter.fetch("SELECT * from " + dbAdapter.TABLE_NAME);

    if (cursor != null) {
        //new user
        if (cursor.getCount() == 1) {

            String loggedOut = cursor.getString(cursor.getColumnIndex(dbAdapter.LOG_OUT));
            if (loggedOut.equalsIgnoreCase("0")) {
                //User not looged out..continue
                String token = cursor.getString(cursor.getColumnIndex(dbAdapter.TOKEN));
                Toast.makeText(Login.this, "Existing", Toast.LENGTH_SHORT).show();

                Login.this.finish();
                String set_up_status = cursor.getString(cursor.getColumnIndex(dbAdapter.SET_UP_STATUS));

                if (set_up_status.equalsIgnoreCase("pending")) {

                    Intent intent = new Intent(Login.this, Module.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(Login.this, Dashboard.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                }

            } else {
                //user has been forced to login..
                SIGN_IN_TYPE = LOGGED_OUT_USER_TYPE;
            }
        } else {
            //New user account..
            SIGN_IN_TYPE = NEW_USER_TYPE;
        }
    } else {
        Toast.makeText(Login.this, "DB error", Toast.LENGTH_SHORT).show();
        //Do something here
    }
    dbAdapter.close();
    btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            _email = txtEmail.getText().toString().trim();
            _password = txtPassword.getText().toString().trim();
            boolean isFieldSet = true;

            if (!validator.isValidEmail(_email)) {

                txtEmail.setError(Validator.emailErrorMessage);
                isFieldSet = false;
            }

            if (validator.isEmpty(_password)) {
                txtPassword.setError(Validator.defaultErrorMessage);
                isFieldSet = false;
            }

            Toast.makeText(Login.this, "Ready for Async Task", Toast.LENGTH_SHORT).show();

            if (isFieldSet) {
                if (config.isConnectingToInternet()) {

                    AsyncLogin asyncLogin = new AsyncLogin();
                    asyncLogin.execute();
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Login.this);
                    builder.setTitle("Error");
                    builder.setMessage("Oops! Something went wrong!\n\nplease check your internet connection")
                            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            }).setPositiveButton("Retry", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    AsyncLogin asyncLogin = new AsyncLogin();
                                    asyncLogin.execute();
                                }
                            });
                    AlertDialog dialog = builder.create();
                    dialog.show();
                }

            } else {
                return;
            }

        }
    });
    txtForgotPassword.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Login.this, ForgotPassword.class);
            startActivity(intent);
        }
    });

    txtSignUp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(Login.this, SignUp.class);
            startActivity(intent);
        }
    });

}

From source file:com.acrylicgoat.scrumnotes.DailyNotesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (drawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/*from  www  .  j ava 2 s.c  o m*/
    if (item.getItemId() == R.id.save) {
        saveNote();
        return true;
    } else if (item.getItemId() == android.R.id.home) {
        Intent mainIntent = new Intent(getApplicationContext(), DailyNotesActivity.class);
        mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(mainIntent);
    }

    return true;
}

From source file:com.app.ntuc.notifs.MyGcmListenerService.java

private void sendNotifications(String messageBody) {
    Intent intent = new Intent(this, MainActivity2_.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    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.mipmap.ic_launcher).setContentTitle("KPMG").setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:org.roman.findme.MyGcmListenerService.java

void displayMessage(String message) {
    if (MessageActivity.active) {
        MessageActivity.addSenderMessage(message);
    } else {//from w w  w.  ja  v a 2s .c  o  m
        Intent intent = new Intent(this, MessageActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("message", message);
        startActivity(intent);
    }

}

From source file:com.android.messaging.ui.UIIntentsImpl.java

/**
 * Get an intent which takes you to a conversation
 *//*w  ww.j a  v  a 2s . c o m*/
private Intent getConversationActivityIntent(final Context context, final String conversationId,
        final MessageData draft, final boolean withCustomTransition) {
    final Intent intent = new Intent(context, ConversationActivity.class);

    // Always try to reuse the same ConversationActivity in the current task so that we don't
    // have two conversation activities in the back stack.
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // Otherwise we're starting a new conversation
    if (conversationId != null) {
        intent.putExtra(UI_INTENT_EXTRA_CONVERSATION_ID, conversationId);
    }
    if (draft != null) {
        intent.putExtra(UI_INTENT_EXTRA_DRAFT_DATA, draft);

        // If draft attachments came from an external content provider via a share intent, we
        // need to propagate the URI permissions through to ConversationActivity. This requires
        // putting the URIs into the ClipData (setData also works, but accepts only one URI).
        ClipData clipData = null;
        for (final MessagePartData partData : draft.getParts()) {
            if (partData.isAttachment()) {
                final Uri uri = partData.getContentUri();
                if (clipData == null) {
                    clipData = ClipData.newRawUri("Attachments", uri);
                } else {
                    clipData.addItem(new ClipData.Item(uri));
                }
            }
        }
        if (clipData != null) {
            intent.setClipData(clipData);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
    }
    if (withCustomTransition) {
        intent.putExtra(UI_INTENT_EXTRA_WITH_CUSTOM_TRANSITION, true);
    }

    if (!(context instanceof Activity)) {
        // If the caller supplies an application context, and not an activity context, we must
        // include this flag
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    return intent;
}

From source file:at.diamonddogs.util.Utils.java

/**
 * Brings up the MAIN/LAUNCHER activity and clears the top
 *
 * @param context a {@link Context}/*w w  w.  j av a2 s  . c om*/
 */
public static void returnToHome(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setPackage(context.getPackageName());
    List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
    Intent homeIntent = new Intent("android.intent.action.MAIN");
    homeIntent.addCategory("android.intent.category.LAUNCHER");
    homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    homeIntent.setComponent(new ComponentName(context.getPackageName(), activities.get(0).activityInfo.name));
    context.startActivity(homeIntent);
}

From source file:com.abiansoftware.lib.reader.AbianReaderItemActivity.java

@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent intent = new Intent(this, AbianReaderActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);/*from w  ww .ja v  a 2  s.  co m*/

        return true;
    } else if (item.getItemId() == SHARE_ITEM_ID) {
        String shareMessage = getString(R.string.share_message);
        String shareTitle = getString(R.string.share_title);

        AbianReaderItem targetItem = AbianReaderApplication.getData().getItemNumber(m_currentPage);

        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, shareMessage);
        sharingIntent.putExtra(Intent.EXTRA_TEXT, targetItem.getLink());
        startActivity(Intent.createChooser(sharingIntent, shareTitle));

        return true;
    } else if (item.getItemId() == OPEN_BROWSER_ITEM_ID) {
        AbianReaderItem targetItem = AbianReaderApplication.getData().getItemNumber(m_currentPage);

        String url = targetItem.getLink();
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.example.jkgan.pmot.service.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from   w w w .ja  va2  s  .c om
 */
private void sendNotification(final String message, final String title, String id) {

    String url = MyApplication.getApiUrl() + "/promotions/" + id + "?token="
            + MyApplication.getUser().getToken();
    final Promotion[] promotion = { null };

    final OkHttpClient client = new OkHttpClient();

    final Request request = new Request.Builder().url(url).build();

    //        new Thread(new Runnable() {
    //            @Override
    //            public void run() {
    Response response = null;
    try {
        response = client.newCall(request).execute();
        JSONObject jsnObj2 = new JSONObject(response.body().string());

        promotion[0] = new Promotion(jsnObj2.optString("pName"), jsnObj2.optString("description"),
                jsnObj2.optString("id"),
                jsnObj2.getJSONObject("image").getJSONObject("medium").optString("url"),
                jsnObj2.getJSONObject("image").getJSONObject("small").optString("url"),
                jsnObj2.optString("term_and_condition"), jsnObj2.optString("name"),
                jsnObj2.optString("address"), jsnObj2.optString("sId"), getDate(jsnObj2.optString("starts_at")),
                getDate(jsnObj2.optString("expires_at")), jsnObj2.optString("phone"));

        Intent intent = new Intent(getApplicationContext(), PromotionActivity.class);
        intent.putExtra("NAME", promotion[0].getName());
        intent.putExtra("SHOP_ID", promotion[0].getId());
        intent.putExtra("IMAGE", promotion[0].getImage());
        intent.putExtra("DESCRIPTION", promotion[0].getDescription());
        intent.putExtra("TNC", promotion[0].getTnc());
        intent.putExtra("SHOP_NAME", promotion[0].getShop().getName());
        intent.putExtra("ADDRESS", promotion[0].getShop().getAddress());
        intent.putExtra("START", promotion[0].getStarts_at());
        intent.putExtra("EXPIRE", promotion[0].getExpires_at());
        intent.putExtra("PHONE", promotion[0].getShop().getPhone());
        intent.putExtra("SUBSCRIBED", true);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0 /* Request code */,
                intent, PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        if (numMessages >= 1) {
            notificationTitle += (", " + title);

            notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.mipmap.ic_launcher).setContentTitle((numMessages + 1) + " new promotions")
                    .setContentText(notificationTitle).setAutoCancel(true).setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);
            numMessages = 0;

            notificationBuilder.setContentText(message).setNumber(++numMessages);

        } else {
            notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setContentText(message)
                    .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

            notificationTitle = title;
            numMessages++;
            //            notificationBuilder.setContentText(message)
            //                    .setNumber(++numMessages);
        }

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

        // On gnre un nombre alatoire pour pouvoir afficher plusieurs notifications
        notificationManager.notify(notifyID, notificationBuilder.build());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.teleca.jamendo.activity.PlayerActivity.java

/**
 * Launch this Activity from the outside, with defined playlist
 *
 * @param c context from which Activity should be started
 * @param a playlist to be played// w w w .j  a  v  a  2s .  c  o m
 */
public static void launch(Context c, Playlist playlist) {
    Intent intent = new Intent(c, PlayerActivity.class);
    intent.putExtra("playlist", playlist);

    /*
     * For example, consider a task consisting of the activities: 
     * A, B, C, D. If D calls startActivity() with an Intent that
     * resolves to the component of activity B, then C and D will
     * be finished and B receive the given Intent, resulting in 
     * the stack now being: A, B. 
     */
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    c.startActivity(intent);
}