List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP
int FLAG_ACTIVITY_CLEAR_TOP
To view the source code for android.content Intent FLAG_ACTIVITY_CLEAR_TOP.
Click Source Link
From source file:com.digi.android.wva.VehicleInfoService.java
/** * Depending on if the service is currently set as 'connected' * (check value of {@code isConnected} boolean), either call * {@link #startForeground(int, Notification)} to put up the * "service is running" notification, or call * {@link #stopForeground(boolean) stopForeground(true)} to remove the * notification (because the service isn't listening). *//w w w . j a va 2 s.c om * <p>This method is protected, rather than private, due to a bug between JaCoCo and * the Android build tools which causes the instrumented bytecode to be invalid when this * method is private: * http://stackoverflow.com/questions/17603192/dalvik-transformation-using-wrong-invoke-opcode * </p> */ protected void showNotificationIfRunning() { // First, c WvaApplication app = (WvaApplication) getApplication(); if (app != null && app.isTesting()) return; if (isConnected) { NotificationCompat.Builder builder; builder = new NotificationCompat.Builder(getApplicationContext()); PendingIntent contentIntent; Intent intent = new Intent(VehicleInfoService.this, DashboardActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); contentIntent = PendingIntent.getActivity(VehicleInfoService.this, 0, intent, 0); builder.setContentTitle("Digi WVA Service") .setContentText("Connected to " + (TextUtils.isEmpty(connectIp) ? "(null)" : connectIp)) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setSmallIcon(R.drawable.notif_small).setOngoing(true).setContentIntent(contentIntent); startForeground(NOTIF_ID, builder.build()); } else { try { stopForeground(true); } catch (Exception e) { // Might happen if startForeground not called before e.printStackTrace(); } } }
From source file:com.devspark.sidenavigation.meiriyiwen.MainActivity.java
private void invokeActivity4(String title, int resId) { Intent intent = new Intent(this, baseMenuActivity4.class); intent.putExtra(EXTRA_TITLE, title); intent.putExtra(EXTRA_RESOURCE_ID, resId); intent.putExtra(EXTRA_MODE, sideNavigationView.getMode() == Mode.LEFT ? 0 : 1); // 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. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);//from w w w . j a v a 2s . com // no animation of transition overridePendingTransition(0, 0); }
From source file:com.jeremyhaberman.playgrounds.WebPlaygroundDAO.java
@Override public Collection<Playground> getNearby(Context context, GeoPoint location, int maxQuantity) { playgrounds = new ArrayList<Playground>(); String result = swingset.getResources().getString(R.string.error); HttpURLConnection httpConnection = null; Log.d(TAG, "getPlaygrounds()"); try {//from w ww . ja va 2 s. com // Build query URL url = new URL("http://swingsetweb.appspot.com/playground?" + TYPE_PARAM + "=" + NEARBY + "&" + LATITUDE_PARAM + "=" + location.getLatitudeE6() + "&" + LONGITUDE_PARAM + "=" + location.getLongitudeE6() + "&" + MAX_PARAM + "=" + Integer.toString(maxQuantity)); httpConnection = (HttpURLConnection) url.openConnection(); httpConnection.setConnectTimeout(15000); httpConnection.setReadTimeout(15000); StringBuilder response = new StringBuilder(); if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { // Read results from the query BufferedReader input = new BufferedReader( new InputStreamReader(httpConnection.getInputStream(), "UTF-8")); String strLine = null; while ((strLine = input.readLine()) != null) { response.append(strLine); } input.close(); } // Parse to get translated text JSONArray jsonPlaygrounds = new JSONArray(response.toString()); int numOfPlaygrounds = jsonPlaygrounds.length(); JSONObject jsonPlayground = null; for (int i = 0; i < numOfPlaygrounds; i++) { jsonPlayground = jsonPlaygrounds.getJSONObject(i); playgrounds.add(toPlayground(jsonPlayground)); } } catch (Exception e) { Log.e(TAG, "Exception", e); Intent errorIntent = new Intent(context, Playgrounds.class); errorIntent.putExtra("Exception", e.getLocalizedMessage()); errorIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(errorIntent); } finally { if (httpConnection != null) { httpConnection.disconnect(); } } Log.d(TAG, " -> returned " + result); return playgrounds; }
From source file:com.example.sabeeh.helloworld.AuthService.java
/** * Handles logging the user out including: * -deleting cookies so their login with a provider won't be cached in the web view * -removing the userdata from the shared preferences * -setting the current user object on the client to logged out * -optionally redirects to the login page if requested * @param shouldRedirectToLogin//from ww w . j a v a2s . c o m */ public void logout(boolean shouldRedirectToLogin) { //Clear the cookies so they won't auto login to a provider again CookieSyncManager.createInstance(mContext); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); //Clear the user id and token from the shared preferences ClearcacheUserToken(); //Clear the user and return to the auth activity mClient.logout(); //Take the user back to the auth activity to relogin if requested if (shouldRedirectToLogin) { Intent logoutIntent = new Intent(mContext, LoginActivity.class); logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(logoutIntent); } }
From source file:me.piebridge.prevent.ui.UserGuideActivity.java
private boolean donateViaWeChat() { File qrCode = getQrCode();/* ww w . ja v a 2 s .co m*/ if (qrCode == null) { return false; } try { FileUtils.dumpFile(getAssets().open("wechat.png"), qrCode); } catch (IOException e) { UILog.d("cannot dump wechat", e); return false; } refreshQrCode(qrCode); showDonateDialog(); Intent intent = new Intent("com.tencent.mm.action.BIZSHORTCUT"); intent.setPackage("com.tencent.mm"); intent.putExtra("LauncherUI.From.Scaner.Shortcut", true); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); for (int i = 0; i < 0x3; ++i) { Toast.makeText(this, R.string.select_qr_code, Toast.LENGTH_LONG).show(); } } catch (Throwable t) { // NOSONAR hideDonateDialog(); } return true; }
From source file:me.gpelaez.cordova.plugins.ibeacon.GPIBeacon.java
/** * + * Issues a notification to inform the user that server has sent a * message. +//w ww .j a va2s.c om * @throws JSONException */ @SuppressLint("InlinedApi") private static void createNotification(Context context, JSONObject json) throws JSONException { Bundle extra = new Bundle(); extra.putString("json", json.toString()); Intent notificationIntent = new Intent(activity, BeaconNotificationHandler.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("beacon", extra); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setDefaults(Notification.DEFAULT_ALL).setSmallIcon(context.getApplicationInfo().icon) .setWhen(System.currentTimeMillis()).setTicker(json.getString("title")) .setContentTitle(json.getString("message")).setContentIntent(contentIntent); String message = json.getString("message"); if (message != null) { mBuilder.setContentText(message); } else { mBuilder.setContentText("<missing message content>"); } mBuilder.addAction(context.getApplicationInfo().icon, json.getString("message"), contentIntent); ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)) .notify((String) getAppName(context), NOTIFICATION_ID, mBuilder.build()); }
From source file:com.perm.DoomPlay.PlayingService.java
private Notification createNotification() { Intent intentActivity;/*from w ww. j av a2 s. co m*/ if (SettingActivity.getPreferences(SettingActivity.keyOnClickNotif)) { intentActivity = new Intent(FullPlaybackActivity.actionReturnFull); intentActivity.setClass(this, FullPlaybackActivity.class); intentActivity.putExtra(FileSystemActivity.keyMusic, audios); } else { intentActivity = FullPlaybackActivity.getReturnSmallIntent(this, audios); } intentActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Notification notification = new Notification(); notification.contentView = getNotifViews(R.layout.notif); notification.flags |= Notification.FLAG_FOREGROUND_SERVICE; notification.contentIntent = PendingIntent.getActivity(this, 0, intentActivity, PendingIntent.FLAG_UPDATE_CURRENT); notification.icon = isPlaying ? R.drawable.status_icon_pause : R.drawable.status_icon_play; return notification; }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(TAG, "Received start id " + startId + ": " + intent); if (intent != null) { try { params = new JSONObject(intent.getStringExtra("params")); headers = new JSONObject(intent.getStringExtra("headers")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace();/*from w ww .j a va 2 s. c om*/ } url = intent.getStringExtra("url"); stationaryRadius = Float.parseFloat(intent.getStringExtra("stationaryRadius")); distanceFilter = Integer.parseInt(intent.getStringExtra("distanceFilter")); scaledDistanceFilter = distanceFilter; desiredAccuracy = Integer.parseInt(intent.getStringExtra("desiredAccuracy")); locationTimeout = Integer.parseInt(intent.getStringExtra("locationTimeout")); isDebugging = Boolean.parseBoolean(intent.getStringExtra("isDebugging")); notificationTitle = intent.getStringExtra("notificationTitle"); notificationText = intent.getStringExtra("notificationText"); // Build a Notification required for running service in foreground. Intent main = new Intent(this, BackgroundGpsPlugin.class); main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(notificationTitle); builder.setContentText(notificationText); builder.setSmallIcon(android.R.drawable.ic_menu_mylocation); builder.setContentIntent(pendingIntent); Notification notification; if (android.os.Build.VERSION.SDK_INT >= 16) { notification = buildForegroundNotification(builder); } else { notification = buildForegroundNotificationCompat(builder); } notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR; startForeground(startId, notification); } Log.i(TAG, "- url: " + url); Log.i(TAG, "- params: " + params.toString()); Log.i(TAG, "- headers: " + headers.toString()); Log.i(TAG, "- stationaryRadius: " + stationaryRadius); Log.i(TAG, "- distanceFilter: " + distanceFilter); Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy); Log.i(TAG, "- locationTimeout: " + locationTimeout); Log.i(TAG, "- isDebugging: " + isDebugging); Log.i(TAG, "- notificationTitle: " + notificationTitle); Log.i(TAG, "- notificationText: " + notificationText); this.setPace(false); //We want this service to continue running until it is explicitly stopped return START_REDELIVER_INTENT; }
From source file:com.appybite.customer.AllowedHotels.java
private void updateLCD() { if (PRJFUNC.mGrp == null) { PRJFUNC.resetGraphValue(this); }//from w w w.ja v a 2s.co m options = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.bg_default_depart) .showImageForEmptyUri(R.drawable.bg_default_depart).showImageOnFail(R.drawable.bg_default_depart) .cacheInMemory(false).cacheOnDisc(true).bitmapConfig(Bitmap.Config.RGB_565).build(); optionsForBg = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.bg_default_restaurant) .showImageForEmptyUri(R.drawable.bg_default_restaurant) .showImageOnFail(R.drawable.bg_default_restaurant).cacheInMemory(false).cacheOnDisc(true) .bitmapConfig(Bitmap.Config.RGB_565).build(); tvHotelHeaderName = (TextView) findViewById(R.id.tvHotelHeaderName); tvHotelHeaderName.setSelected(true); btBack = (Button) findViewById(R.id.btBack); btBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { onBackPressed(); } }); btHotelChoose = (Button) findViewById(R.id.btHotelChoose); btHotelChoose.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String choosedHotelId = PrefValue.getString(AllowedHotels.this, R.string.pref_hotel_id); if (choosedHotelId != null && choosedHotelId.length() != 0) { Intent i = null; if (DeviceUtil.isTabletByRes(AllowedHotels.this)) { i = new Intent(AllowedHotels.this, MainActivity_Tab.class); } else { i = new Intent(AllowedHotels.this, MainActivity.class); } ImageLoader.getInstance().stop(); ImageLoader.getInstance().clearMemoryCache(); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); finish(); } } }); llHotelList = (LinearLayout) findViewById(R.id.llHotelList); if (DeviceUtil.isTabletByRes(this)) { ivHotelLogo = (ImageView) findViewById(R.id.ivHotelLogo); ivHotelBg = (ImageView) findViewById(R.id.ivHotelBg); tvHotelName = (TextView) findViewById(R.id.tvHotelName); tvTime = (TextView) findViewById(R.id.tvTime); tvTime.setText("0:00"); ImageLoader.getInstance().displayImage(PrefValue.getString(this, R.string.pref_hotel_bg), ivHotelBg, optionsForBg, animateFirstListener); ImageLoader.getInstance().displayImage(PrefValue.getString(this, R.string.pref_hotel_logo), ivHotelLogo, null, animateFirstListener); tvHotelName.setText(PrefValue.getString(this, R.string.pref_hotel_name)); } setTitle("Welcome"); }
From source file:com.vendsy.bartsy.venue.GCMIntentService.java
/** * To generate a notification to inform the user that server has sent a message. * // www. j ava2s.c o m * @param count * @param count */ private static void generateNotification(Context context, String message, String count) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainActivity.class); // 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, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; try { int countValue = Integer.parseInt(count); notification.number = countValue; } catch (NumberFormatException e) { e.printStackTrace(); } // // Play default notification sound notification.defaults = Notification.DEFAULT_SOUND; notificationManager.notify(0, notification); }