android-pendingintent

Intent - if activity is running, bring it to front, else start a new one (from notification)

浪子不回头ぞ 提交于 2019-12-17 05:45:49
问题 My app has notifications, which - obviously - without any flags, start a new activity every time so I get multiple same activities running on top of each other, which is just wrong. What I want it to do is to bring the activity specified in the notifications pending intent, to the front if it is already running, otherwise start it. So far, the intent/pending intent for that notification I have is private static PendingIntent prepareIntent(Context context) { Intent intent = new Intent(context,

PendingIntent works correctly for the first notification but incorrectly for the rest

Deadly 提交于 2019-12-17 03:23:33
问题 protected void displayNotification(String response) { Intent intent = new Intent(context, testActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); Notification notification = new Notification(R.drawable.icon, "Upload Started", System.currentTimeMillis()); notification.setLatestEventInfo(context, "Upload", response, pendingIntent); nManager.notify((int)System.currentTimeMillis(), notification); } This function will be

Calling startActivity() from outside of an Activity?

痞子三分冷 提交于 2019-12-17 02:26:05
问题 I'm using an AlarmManager to trigger an intent that broadcasts a signal. The following is my code: AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, Wakeup.class); try { PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0); Long elapsed += // sleep time; mgr.set(AlarmManager.RTC_WAKEUP, elapsed, pi); } catch(Exception r) { Log.v(TAG, "RunTimeException: " + r); } I'm calling this code from an Activity , so I don't know how I could be

date and time not working in Alarm Manager

假装没事ソ 提交于 2019-12-14 03:22:41
问题 I'm having trouble working with the AlarmManager . I want to run AlarmManager using Calendar at a specific time. But the calendar doesn't work and AlarmManager always runs regardless of the time taken from the calendar. AlarmManager mAlarmManger = (AlarmManager) Objects.requireNonNull(activity).getSystemService(view.getContext().ALARM_SERVICE); Intent intent = new Intent(activity, MyReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 0, intent, PendingIntent

Why onMessageReceived() method is not passing intent properly when the app is in background?

落爺英雄遲暮 提交于 2019-12-14 03:08:18
问题 Actually I'm trying to pass intent to an activity on click of the push-notification and it's working fine when the app is present in foreground .But when the app is in background although I'm receiving the push-notification without any problem but by clicking that notification I'm not getting intent in the activity . I tried to refer some questions in SO and tried adding flags like PendingIntent.FLAG_UPDATE_CURRENT , PendingIntent.FLAG_ONE_SHOT ,then in intent (Intent.FLAG_ACTIVITY_NEW_TASK

PendingIntent not recreating activity (with Extras) when it is already on history stack top

寵の児 提交于 2019-12-13 19:17:42
问题 I am trying to start an Activity A from a Notification Button (using PendingIntent). When I tap on this Notification Button and A is on top of history stack, it just not behave correctly: What it should do: Activity A must duplicated on historystack, this way: When activity A is on top of history stack Before: [ A, ... old activities ... ] After: [ A, A, ... old activities ... ] When activity A is not on top of history stack (default behavior) Before: [ B, ... old activities ... ] After: [ A,

Widgets and setOnClickPendingIntent

久未见 提交于 2019-12-13 18:23:44
问题 Complete android development newbie here, be warned. I'm trying to develop a homescreen widget that allows you to tap the widget to call a predefined number. I can create the widget and add it to the homescreen just fine, however, when I try to make the widget clickable using setOnClickPendingIntent , it does not launch the activity. The code I am using is provided below: public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { RemoteViews remoteViews =

Get app package name selected by user for sharing using 'Intent.ACTION_SEND'

痴心易碎 提交于 2019-12-13 17:59:50
问题 I am using following code to share text Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_TEXT, "share test"); startActivity(Intent.createChooser(sharingIntent, "Share using")); I want to know package name of the app chosen by user to share. I have tried doing it using IntentSender for 5.1+ devices using following code Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.putExtra(Intent.EXTRA_TEXT,

Intent.FLAG_ACTIVITY_FORWARD_RESULT and PendingIntent

橙三吉。 提交于 2019-12-13 15:21:51
问题 I want to receive an Intent instance from an Activity launched by an AlarmManager with a pendingIntent. I have the Activity A launch the Activity B through alarmManager with pendingIntent like this : PendingIntent pendingIntent = PendingIntent.getActivity(this, position, intentListAlarmActivityToWakeUpActivity, 0); Log.i("position", position +""); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, hourAlarm);

Start multiple activities from Notification via PendingIntent

ⅰ亾dé卋堺 提交于 2019-12-13 11:09:38
问题 I'd like to start multiple activities when press on Notification. I didn't find any docs about how to set multiple intents in a single PendingIntent . One solution could be to start next activity in the first one's onCreate() and so forth, but I don't like this, maybe there is something else. 回答1: Finally, I got the answer for this - it's pretty trivial, just using method getActivities() to the PendingIntent like so: Intent myIntent1= new Intent(ctx, MyActivity1.class); myIntent1.setFlags