Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to persistently save PendingIntent provided by another application

let's say I want to implement an app which exposes services to other apps (like Google Play Services..).

potential apps would register to my special events associated with my services, and would be notified at the right time.

I was thinking to implement this exactly like Google did with the Google Play services:

thanks to Android Inter-Process Communication, other apps could bind to my app Service, and by that - pass to my app PendingIntent "callback" that I could execute for them at the right time.

now, I'll get to the problem:

  • my app process currently running (in background) and holding reference to PendingIntent provided by other app.

  • now, from some reason (System decisions/ user explicitly) my process been stopped.

  • my process cumming back in some point, and come back to "do it's thing.."

in that point - I lost reference to the PendingIntent provided to me before, and I don't see any way in the API to retrieve back reference to it.

also I don't see any way to save persistently(database/sharedPreferences/file system) saving the pending intent for latter on usage

my questions are:

  • is it possible to store pending intent persistently somehow?

  • is it possible to "get back" reference to the same pending intent I already got before?

  • if not, is there any other suggestion to implement such thing as I described?

like image 334
Tal Kanel Avatar asked Jan 12 '14 20:01

Tal Kanel


People also ask

How do I cancel or modify a pending intent?

If you only need one PendingIntent active at a time for any of the Intents you will use, then you can alternatively use the flags FLAG_CANCEL_CURRENT or FLAG_UPDATE_CURRENT to either cancel or modify whatever current PendingIntent is associated with the Intent you are supplying.

What is a pendingintent?

A pendingIntent wraps a regular intent that can be passed to a foreign application (like AlarmManger or NotificationManager etc..) where you are granting that application the right to perform the action. Normally a pendingIntent is used with AlarmManager or NotificationManager. PendingIntent must need a regular intent to be created.

What is pending intent in Salesforce?

The moral of the story is this, PendingIntent is an intent that will perform at a later time or in other words PendingIntent specifies an action to take in future. The main differences between a pendingIntent and regular intent is pendingIntent will perform at a later time where Normal/Regular intent starts immediately.

How can I have multiple pendingintents active at the same time?

There are two typical ways to deal with this. If you truly need multiple distinct PendingIntent objects active at the same time (such as to use as two notifications that are both shown at the same time), then you will need to ensure there is something that is different about them to associate them with different PendingIntents.


1 Answers

is it possible to store pending intent persistently somehow?

No.

is it possible to "get back" reference to the same pending intent I already got before?

Not from the OS. If you have some other "bootstrap" communications method, you could ask the original app to re-supply a PendingIntent. For example, you could send a broadcast stating that you need apps to re-register; apps using your service would listen for such broadcasts and give you a fresh PendingIntent.

Or, skip the PendingIntent entirely and use something else. For example, apps could export a BroadcastReceiver. Where they would register a PendingIntent in your current plan, they would simply provide you the ComponentName of the BroadcastReceiver. That information (package name and class name) could be persisted, and you could then send a broadcast to that specific ComponentName as needed.

Note that with any strategy that involves persistence, you will need to deal with the cases where the client app has been upgraded and the old stored details are now incorrect (e.g., they refactored their code, and the old ComponentName is now invalid).

like image 122
CommonsWare Avatar answered Sep 30 '22 03:09

CommonsWare