0

I'm making an application that detects incoming text messages.

When a message is received, the application must perform a certain action, depending on the sender and the content.

The problem is that the application must work at all times. Detecting messages works through a BroadcastReceiver class. Via a Toast message I can see that the application (open or closed) receives the message.

The problem then is that I must perform certain actions, which are stored in a local database (DB40). But I can't access the database when the application is closed.

So, how can I perform database access and run other code (like making the phone vibrate, or play a ringtone) when the application is closed?

Thanks in advance

3 Answers3

0

You need to run a service to perform all the task even app is closed.

Just go through with few sample and study: http://developer.android.com/guide/components/services.html

DcodeChef
  • 1,550
  • 13
  • 17
0

You can access the DataBase... because you are getting the context from the receiver, from the context create the instance of the Database and go further according to your requirement..

Check this...

Community
  • 1
  • 1
Jagadesh Seeram
  • 2,630
  • 1
  • 16
  • 29
  • I already tried that, but I'll try combining it with services for further code too. thanks for your response =) – user2153628 Dec 12 '13 at 14:17
0

Do you know about Services?

You can use service as back-end to perform action on incoming messages or can use database.

Database need only 'Context' object for read/write and service provide 'Context' object by 'getApplicationContext()' method.

If you have any ambiguity about answer, just give me your little code, i will give you back with solution.

Arfan Mirza
  • 668
  • 1
  • 14
  • 24