Pergunta

i have an android application that handles a sql-lite database and i need to to beable save a unique PendingIntent, and a unique long for every rowId in the database. The PendingIntent and long have to be reachable from all the applications classes so i can easily 1)retrieve them 2)cancel it(the PendingIntent) and 3)change them from anywhere is the applications code.

i am sure someone can help! thankyou :)

PS. if it makes any difference i have 2 sql databases that both need this.

Foi útil?

Solução

I would suggest:

  1. You have a service that gets loaded on startup with BOOT_COMPLETED event.
  2. The service polls the db and creates a map of special objects, which contain PendingIntent, your unique long and whatever more.
  3. From the activity you bind to a service and ask it to do somethings, would it be returning an intent, or creating new or whatever.
  4. Application class can know about the service from the activity, you have binded to the service.

I'm not sure the service is necessary here. If your work with pending intents begins from the concreate activity, you can simplify this solution with using Singleton pattern for the class, which contains the pending intents data.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top