List of usage examples for android.app PendingIntent getActivity
public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:at.alladin.rmbt.android.test.RMBTService.java
private void addNotificationIfTestRunning() { if (isTestRunning() && !bound) { final Resources res = getResources(); final PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), RMBTMainActivity.class), 0); final Notification notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.stat_icon_test) .setContentTitle(res.getText(R.string.test_notification_title)) .setContentText(res.getText(R.string.test_notification_text)) .setTicker(res.getText(R.string.test_notification_ticker)).setContentIntent(contentIntent) .build();/*ww w .j av a2s . c o m*/ startForeground(NotificationIDs.TEST_RUNNING, notification); } }
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
@SuppressWarnings("deprecation") public Notification createNotification(Bundle settings, JSONObject obj) { // notifications[i] = api.normalizeAPI({ // 'string': { // mandatory: ['title', 'body'], // defaults: {'icon':'icon'} // },//from w w w.ja va2 s . c om // // 'number': { // mandatory: ['id', 'timeMillisSince1970'], // // the number of ms after which we start prioritising more recent // things above you. // defaults: {'epsilon': 1000 * 60 * 24 * 365} // }, // // 'boolean': { // defaults: { // 'vibrate': false, // 'sound': false // } // } int icon = settings.getInt("notification_icon", -1); if (icon == -1) { Log.e(C.TAG, "Need a notification_icon resource in the meta-data of LocalNotificationsAlarmReceiver"); return null; } Notification n = new Notification(); n.icon = icon; n.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; long alarmTime = obj.optLong("timeMillisSince1970"); long displayTime = obj.optLong("displayTimestamp", alarmTime); n.when = displayTime; n.tickerText = obj.optString("body"); n.setLatestEventInfo(mContext, obj.optString("title"), obj.optString("body"), null); if (obj.optBoolean("vibrate")) { n.defaults |= Notification.DEFAULT_VIBRATE; } if (obj.optBoolean("sound")) { n.defaults |= Notification.DEFAULT_SOUND; } String uriString = settings.getString("content_uri_prefix"); if (uriString == null) { Log.e(C.TAG, "Need a content_uri_prefix in the meta-data of LocalNotificationsAlarmReceiver"); return null; } if (uriString.contains("%d")) { uriString = String.format(uriString, obj.optInt("id")); } Uri uri = Uri.parse(uriString); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(uri); n.contentIntent = PendingIntent.getActivity(mContext, 23, intent, PendingIntent.FLAG_ONE_SHOT); return n; }
From source file:com.pinplanet.pintact.GcmIntentService.java
private void sendChatNotification(String customData) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); JSONObject jsonObject = null;//from w w w. j a v a 2 s . com JSONObject chatObject = null; GroupDTO groupDTO = new GroupDTO(); String chatMessage = "New Chat Message"; String groupId = ""; try { jsonObject = new JSONObject(customData); Log.d(TAG, "groupId: " + jsonObject.getString("groupId")); groupId = jsonObject.getString("groupId"); groupDTO.setId(jsonObject.getString("groupId")); SingletonLoginData.getInstance().setCurGroup(groupDTO); Log.d(TAG, "message: " + jsonObject.getString("message")); chatObject = jsonObject.getJSONObject("message"); chatMessage = chatObject.getString("content"); } catch (JSONException e) { Log.d(TAG, "sendChatNotification error: " + e.toString()); e.printStackTrace(); } //Intent it = new Intent(this, PushNotificationActivity.class); Intent it = new Intent(this, GroupContactsActivity.class); it.putExtra("groupId", groupId); it.putExtra("OpenThreads", true); //it.putExtra(LeftDeckActivity.SELECTED_OPTIONS, LeftDeckActivity.OPTION_NOTIFY); // add the following line would show Pintact to the preview page. // it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, it, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("New Message") .setStyle(new NotificationCompat.BigTextStyle().bigText(chatMessage)) .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }).setAutoCancel(true) .setContentText(chatMessage); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); SingletonLoginData.getInstance().mNotificationManager = mNotificationManager; }
From source file:audio.lisn.service.MediaNotificationManager.java
/** * Update the state based on a change on the session token. Called either when * we are running for the first time or when the media session owner has destroyed the session * (see {@link android.media.session.MediaController.Callback#onSessionDestroyed()}) *//*from w ww . j av a2s . com*/ /* private void updateSessionToken() { MediaSession.Token freshToken = mService.getSessionToken(); if (mSessionToken == null || !mSessionToken.equals(freshToken)) { if (mController != null) { mController.unregisterCallback(mCb); } mSessionToken = freshToken; mController = new MediaController(mService, mSessionToken); mTransportControls = mController.getTransportControls(); if (mStarted) { mController.registerCallback(mCb); } } } */ private PendingIntent createContentIntent() { Intent openUI = new Intent(mService, PlayerControllerActivity.class); openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.pulp.campaigntracker.gcm.GcmIntentService.java
@SuppressWarnings("unchecked") private void sendNotification(GCM msg) { if (msg != null) { int index = 1; mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(); bigText.bigText(msg.getMessage()); bigText.setBigContentTitle(msg.getTitle()); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mNotificationCount = mAppPref.getInt("Notif_Number_Constant", 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_app_icon).setContentTitle(msg.getTitle()) .setStyle(bigText).setContentText(msg.getMessage()).setSound(uri) .setNumber(mNotificationCount + 1); mAppPref.edit().putInt("Notif_Number_Constant", (mNotificationCount + 1)).commit(); try {/*from w ww.j av a2s . c o m*/ if ((ArrayList<UserNotification>) ObjectSerializer .deserialize(mAppPref.getString(ConstantUtils.NOTIFICATION, "")) == null) { notifyList = new ArrayList<UserNotification>(); } else { notifyList = (ArrayList<UserNotification>) ObjectSerializer .deserialize(mAppPref.getString(ConstantUtils.NOTIFICATION, "")); } } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } notification = new UserNotification(); notification.setTitle(msg.getTitle()); notification.setMessage(msg.getMessage()); notification.setNotifyTime(System.currentTimeMillis()); notifyList.add(notification); try { mAppPref.edit().putString(ConstantUtils.NOTIFICATION, ObjectSerializer.serialize(notifyList)) .commit(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Intent newIntent = null; ConstantUtils.SYNC_INTERVAL = 30 * 60 * 1000; // if (mAppPref.getString(ConstantUtils.USER_ROLE, "") // .equals(LoginData.)) { // newIntent = new Intent(getBaseContext(), // UserMotherActivity.class); // Intent i = new Intent(this, PeriodicService.class); // this.startService(i); // } else { newIntent = new Intent(getBaseContext(), SplashScreen.class); Intent i = new Intent(this, PeriodicService.class); this.startService(i); // } PendingIntent contentIntent = PendingIntent.getActivity(GcmIntentService.this, 0, newIntent, 0); mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(index, mBuilder.build()); Intent intent = new Intent(); intent.setAction("googleCloudMessage"); sendBroadcast(intent); } }
From source file:at.ac.uniklu.mobile.sportal.notification.GCMCampusService.java
private void notifyUser() { try {// w ww . j a v a 2s. c o m NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); // get all notifications since last check time List<Notification> notifications = Studentportal.getSportalClient() .getNotifications(Preferences.getNotificationsLastCheckDate(this, preferences)); // set last check time to current time Preferences.setNotificationsLastCheckDate(this, preferences, new Date()); Collections.reverse(notifications); for (Notification n : notifications) { Log.i(TAG, n.toString()); String title = n.getName(); String text = null; Intent i = null; switch (n.getType()) { case UNKNOWN: // skip unknown notification (might be a new type for a newer app version) continue; case INSKRIPTION: text = getString(R.string.notification_inskription); break; case LV_AUFGENOMMEN: text = getString(R.string.notification_lv_aufgenommen); Studentportal.getSportalClient().clearLehrveranstaltungen(); i = new Intent(this, CourseListActivity.class); break; case LV_STATUS: text = getString(R.string.notification_lv_status) + " " + n.getValue(); Studentportal.getSportalClient().clearLehrveranstaltungen(); i = new Intent(this, CourseListActivity.class); break; case LV_UMMELDUNG: text = getString(R.string.notification_lv_ummeldung) + " " + n.getValue(); Studentportal.getSportalClient().clearLehrveranstaltungen(); i = new Intent(this, CourseListActivity.class); break; case PRUEFUNG_ANMELDUNG: text = getString(R.string.notification_pruefung_anmeldung); Studentportal.getSportalClient().clearPruefungen(); i = new Intent(this, ExamListActivity.class); break; case NOTE_NEU: text = getString(R.string.notification_note_neu) + " " + n.getValue(); Studentportal.getSportalClient().clearNoten(); i = new Intent(this, GradeListActivity.class); break; case STUDIUM_ABSCHLUSS: text = getString(R.string.notification_studium_abschluss); break; case STUDIUM_ABSCHNITTSABSCHLUSS: text = getString(R.string.notification_studium_abschnittsabschluss); break; case STUDIUM_STEOPERFUELLT: text = getString(R.string.notification_steoperfuellt); break; } NotificationCompat.Builder nb = GCMUtils.getDefaultNotification(this); nb.setTicker(title); nb.setContentTitle(title); nb.setContentText(text); if (i == null) { /* intent must not be null on Android 2.3, even if the notification * doesn't do anything when selected; else, an exception gets thrown: * java.lang.IllegalArgumentException: contentIntent required */ i = new Intent(); } /* Pass System.currentTimeMillis() as requestId to make every pending intent unique. Otherwise, * they would overwrite each other if the intent is the same and not all notification (if shown * at the same time) would trigger the desired action when selected. */ nb.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(), i, Intent.FLAG_ACTIVITY_NEW_TASK)); notificationManager.notify(Studentportal.NOTIFICATION_GCM_NOTIFICATION + n.getType().ordinal(), nb.build()); } } catch (Exception e) { Analytics.onError(Analytics.ERROR_NOTIFICATIONS_REQUEST, e); } }
From source file:cm.aptoide.pt.DownloadQueueService.java
private void setFinishedNotification(int apkidHash, String localPath) { String apkid = notifications.get(apkidHash).get("apkid"); int size = Integer.parseInt(notifications.get(apkidHash).get("intSize")); String version = notifications.get(apkidHash).get("version"); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification); contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification); contentView.setTextViewText(R.id.download_notification_name, getString(R.string.finished_download_message) + " " + apkid + " v." + version); contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, size * KBYTES_TO_BYTES, false); Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid)); onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab"); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.putExtra("localPath", localPath); onClick.putExtra("apkid", apkid); onClick.putExtra("apkidHash", apkidHash); onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate"))); /*Changed by Rafael Campos*/ onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version")); Log.d("Aptoide-DownloadQueuService", "finished notification apkidHash: " + apkidHash + " localPath: " + localPath); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0); Notification notification = new Notification(R.drawable.ic_notification, getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.contentView = contentView; // Set the info for the notification panel. notification.contentIntent = onClickAction; // notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Send the notification. // We use the position because it is a unique number. We use it later to cancel. notificationManager.notify(apkidHash, notification); // Log.d("Aptoide-DownloadQueueService", "Notification Set"); }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java
public static String create(Context p_context, DatabaseAdapter p_dba, DefaultHttpClient p_http) { startTimestamp = System.currentTimeMillis(); if (isRunning == true) { isCanceled = true;/* w w w . java 2s . c o m*/ isRunning = false; } isRunning = true; boolean recordSyncTime = true; dba = p_dba; db = dba.db(); em = dba.em(); http_client = p_http; context = p_context; last_sync_ts = MyPreferences.getFlowzrLastSync(context); FLOWZR_BASE_URL = "https://" + MyPreferences.getSyncApiUrl(context); FLOWZR_API_URL = FLOWZR_BASE_URL + "/financisto3/"; nsString = MyPreferences.getFlowzrAccount(context).replace("@", "_"); //urlsafe Log.i(TAG, "init sync engine, last sync was " + new Date(last_sync_ts).toLocaleString()); //if (true) { if (!checkSubscriptionFromWeb()) { Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.icon) .setTicker(context.getString(R.string.flowzr_subscription_required)) .setContentTitle(context.getString(R.string.flowzr_sync_error)) .setContentText(context.getString(R.string.flowzr_subscription_required, MyPreferences.getFlowzrAccount(context))) .setContentIntent(pendingIntent).setAutoCancel(true).build(); notificationManager.notify(0, notification); Log.w("flowzr", "subscription rejected from web"); isCanceled = true; MyPreferences.unsetAutoSync(context); return null; } else { mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Sets an ID for the notification, so it can be updated mNotifyBuilder = new NotificationCompat.Builder(context).setAutoCancel(true) .setContentTitle(context.getString(R.string.flowzr_sync)) .setContentText(context.getString(R.string.flowzr_sync_inprogress)) .setSmallIcon(R.drawable.icon); } if (!isCanceled) { notifyUser("fix created entities", 5); fixCreatedEntities(); } /** * pull delete */ if (!isCanceled) { notifyUser(context.getString(R.string.flowzr_sync_receiving) + " ...", 10); try { pullDelete(last_sync_ts); } catch (Exception e) { sendBackTrace(e); recordSyncTime = false; } } /** * push delete */ if (!isCanceled) { notifyUser(context.getString(R.string.flowzr_sync_sending) + " ...", 15); try { pushDelete(); } catch (Exception e) { sendBackTrace(e); recordSyncTime = false; } } /** * pull update */ if (!isCanceled && last_sync_ts == 0) { notifyUser(context.getString(R.string.flowzr_sync_receiving) + " ...", 20); try { pullUpdate(); } catch (IOException e) { sendBackTrace(e); recordSyncTime = false; } catch (JSONException e) { sendBackTrace(e); recordSyncTime = false; } catch (Exception e) { sendBackTrace(e); recordSyncTime = false; } } /** * push update */ if (!isCanceled) { notifyUser(context.getString(R.string.flowzr_sync_sending) + " ...", 35); try { pushUpdate(); } catch (ClientProtocolException e) { e.printStackTrace(); sendBackTrace(e); recordSyncTime = false; } catch (IOException e) { e.printStackTrace(); sendBackTrace(e); recordSyncTime = false; } catch (JSONException e) { e.printStackTrace(); sendBackTrace(e); recordSyncTime = false; } catch (Exception e) { e.printStackTrace(); recordSyncTime = false; } } /** * pull update */ if (!isCanceled && last_sync_ts > 0) { notifyUser(context.getString(R.string.flowzr_sync_receiving) + " ...", 20); try { pullUpdate(); } catch (IOException e) { sendBackTrace(e); recordSyncTime = false; } catch (JSONException e) { sendBackTrace(e); recordSyncTime = false; } catch (Exception e) { sendBackTrace(e); recordSyncTime = false; } } notifyUser(context.getString(R.string.integrity_fix), 80); new IntegrityFix(dba).fix(); /** * send account balances boundaries */ if (!isCanceled) { //if (true) { //will generate a Cloud Messaging request if prev. aborted notifyUser(context.getString(R.string.flowzr_sync_sending) + "...", 85); //nm.notify(NOTIFICATION_ID, mNotifyBuilder.build()); ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("action", "balancesRecalc")); nameValuePairs.add(new BasicNameValuePair("last_sync_ts", String.valueOf(last_sync_ts))); String serialNumber = Build.SERIAL != Build.UNKNOWN ? Build.SERIAL : Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); nameValuePairs.add(new BasicNameValuePair("serialNumber", serialNumber)); List<Account> accountsList = em.getAllAccountsList(); for (Account account : accountsList) { nameValuePairs.add(new BasicNameValuePair(account.remoteKey, String.valueOf(account.totalAmount))); Log.i("flowzr", account.remoteKey + " " + String.valueOf(account.totalAmount)); } try { httpPush(nameValuePairs, "balances"); } catch (Exception e) { sendBackTrace(e); } } notifyUser("Widgets ...", 90); AccountWidget.updateWidgets(context); Handler refresh = new Handler(Looper.getMainLooper()); refresh.post(new Runnable() { public void run() { if (currentActivity != null) { //currentActivity.refreshCurrentTab(); } } }); if (!isCanceled && MyPreferences.doGoogleDriveUpload(context)) { notifyUser(context.getString(R.string.flowzr_sync_sending) + " Google Drive", 95); pushAllBlobs(); } else { Log.i("flowzr", "picture upload desactivated in prefs"); } notifyUser(context.getString(R.string.flowzr_sync_success), 100); if (isCanceled == false) { if (recordSyncTime == true) { last_sync_ts = System.currentTimeMillis(); SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); editor.putLong("PROPERTY_LAST_SYNC_TIMESTAMP", last_sync_ts); editor.commit(); } } // mNotificationManager.cancel(NOTIFICATION_ID); isRunning = false; isCanceled = false; if (context instanceof FlowzrSyncActivity) { ((FlowzrSyncActivity) context).setIsFinished(); } return FLOWZR_BASE_URL; }
From source file:com.example.ramap.MainActivity.java
@SuppressWarnings("deprecation") private void Notify(String notificationTitle, String notificationMessage) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); @SuppressWarnings("deprecation") Notification notification = new Notification(R.drawable.ic_check_in, "New Check In", System.currentTimeMillis()); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(MainActivity.this, notificationTitle, notificationMessage, pendingIntent); notificationManager.notify(9999, notification); }
From source file:com.intel.xdk.notification.Notification.java
public void showBusyIndicator() { if (spinner != null) return;//from w w w . j ava2s. c om //get a reference to the service String ns = Context.NOTIFICATION_SERVICE; final NotificationManager mNotificationManager = (NotificationManager) activity.getSystemService(ns); //create the notification instance int icon = activity.getResources().getIdentifier("spinner_n", "drawable", activity.getPackageName());//R.drawable.spinner_n; PackageManager packageManager = activity.getPackageManager(); ApplicationInfo applicationInfo = null; try { applicationInfo = packageManager.getApplicationInfo(activity.getPackageName(), 0); } catch (final NameNotFoundException e) { } final String title = (String) ((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???"); CharSequence tickerText = title + " is busy...";//activity.getString(R.string.app_name) + " is busy..."; long when = System.currentTimeMillis(); final android.app.Notification notification = new android.app.Notification(icon, tickerText, when); //initialize latest event info Context context = activity.getApplicationContext(); CharSequence contentTitle = title + " is busy...";//activity.getString(R.string.app_name) + " is busy..."; CharSequence contentText = "...just a moment please."; Intent notificationIntent = new Intent(activity, activity.getClass()); PendingIntent contentIntent = PendingIntent.getActivity(activity, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); //make notification non-cancellable notification.flags = notification.flags | android.app.Notification.FLAG_NO_CLEAR; //show in status bar mNotificationManager.notify(BUSY_INDICATOR, notification); //animate the icon spinner = new Thread("intel.xdk.notification:showBusyIndicator") { public void run() { //frame pointer int currentFrame = 0; //frame array //int[] frames = new int[]{R.drawable.spinner_ne, R.drawable.spinner_e, R.drawable.spinner_se, R.drawable.spinner_s, R.drawable.spinner_sw, R.drawable.spinner_w, R.drawable.spinner_nw, R.drawable.spinner_n}; int[] frames = new int[] { activity.getResources().getIdentifier("spinner_ne", "drawable", activity.getPackageName()), activity.getResources().getIdentifier("spinner_e", "drawable", activity.getPackageName()), activity.getResources().getIdentifier("spinner_se", "drawable", activity.getPackageName()), activity.getResources().getIdentifier("spinner_s", "drawable", activity.getPackageName()), activity.getResources().getIdentifier("spinner_sw", "drawable", activity.getPackageName()), activity.getResources().getIdentifier("spinner_w", "drawable", activity.getPackageName()), activity.getResources().getIdentifier("spinner_nw", "drawable", activity.getPackageName()), activity.getResources().getIdentifier("spinner_n", "drawable", activity.getPackageName()) }; Thread thisThread = Thread.currentThread(); while (spinner == thisThread) { //loop over the frames, updating the icon every 200 ms currentFrame++; currentFrame %= frames.length; notification.icon = frames[currentFrame]; mNotificationManager.notify(BUSY_INDICATOR, notification); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } //when looping ends, remove notification from status bar mNotificationManager.cancel(BUSY_INDICATOR); } @Override protected void finalize() throws Throwable { //in case the process crashes, try to remove notification from status bar super.finalize(); mNotificationManager.cancel(BUSY_INDICATOR); } }; spinner.start(); }