Question

I am new to android development and I did research on notifications using toast and status bar notification.

And I also managed to execute the code properly to make a notification work!!!

The problem is there are only methods like triggering a notification by clicking a button is available. Other wise I managed to directly call the codes within the method that is called by the button, to make it trigger automatically. But the problem is the view of the corresponding screen is showing up a tleast for a sec and then closing while this notification is triggered. So how can i write a code that just triggers the notification without popping up the screen even for a second.

I need a result like the way the new SMS alert works...And I did a lot of research on this and all I got was about basic notification. So please help as I am new to this!!!

Was it helpful?

Solution

Using a Service would be the "right" way to do it - and if this is a professional app you are writing, then that's the way to go.

Bear in mind you still need some activities in your application, in order to trigger the service.


If you are just experimenting, then maybe what you need is a cheap hack...

Here's the cheap and nasty way to get your proof-of-concept done:

  • either - create a transparent Activity so that nothing is displayed when the activity code gets called.
  • or - create your notification from within the Activity.onCreate() method, and then call finish() at the end of that method. Your activity will never get shown to the user.

To me, it looks like you are just experimenting, and a transparent activity might get you further faster... ymmv

OTHER TIPS

Legendary you need service and handler. Using service you can get data. and using handler you can modify the UI of your app. here you can get more information on it. http://developer.android.com/training/notify-user/display-progress.html

Working with handlers and threads in service, Thread.sleep makes the program to hang?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top