I have an app that starts when the phone starts. In the app I have an option for the user to stop showing a notification from the app. The notification is related to the boot_complete action (it starts a service). I'm wondering how would I stop the App from starting on boot up if the notification is turn off? I'm thinking on setting a shared preference to "No" if the notification is turned off and then check that on the boot complete broadcast. If the preference is set to "No", then nothing will start if it's set to "Yes" then it will start. Is that the best way of doing it or is there a better way to do it?
Yes this is the best way to do this, just implement it in your BroadcastReceiver. I have implemented this multiple times in my apps, it seems to work well.
Related
Could someone please help me figurate how to make an app that has no icon and starts at the startup?
I want it to start in every startup and keep running all the time, because I want to Toast the name of the sender each time there's an incoming SMS.
I'm not sure what you mean by "hidden" as the O/S generally tries to avoid allowing you to hide behavior from the user. What you want to do is discussed in this question Trying to start a service on boot on Android. That will enable you to launch a service and then by watching for the appropriate intents related to SMS messages you can create the toasts you desire.
I am trying to develop an app that should run in the background. I want my app to pop-up a message everyday at a particular time of day. As i read i will have to use 'Service' for this. http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle This link shows an example. But where should my code for pop-up be? I dint understand well from the above link. Another question i have is will the app continue to run even after a reboot?
you can show a notification from the app to show pop up msgs, that is the best practice. though showing dialog is also possible. code will be in service only. see this link
And to keep your application running after reboot you will have to register for BOOT_COMPLETED broadcast and whenever you receive that broadcast, you will have to launch your service again. see this link
This requirement is only satisfied if the app is running in the background.And if the Screen is turned on if the user presses to check any notifications then an Asynctask is called if the app is running in the background and makes a call to the server.
I have tried using Broadcast Receiver when screen on and tried to execute, it works only if the app is on the front screen after pressing the home button .And then if the user presses Power button after an hour then nothing happens .
Basically I am not sure if the app is being killed after sometime when in background. Please help me.I am a noob in Android and this functionality is something I thought most of the developers might be using but I did not see anything except service calls and I really did not want any service/alarm-manager as I don't want it to work continuously.
TIA
how to make server call whenever device screen is turned ON without Service
This is not possible. ACTION_SCREEN_ON is a broadcast that can only be received by a BroadcastReceiver registered via registerReceiver(). So, unless you are the foreground activity, the only way you can receive this broadcast is via an always-running service, which is not a good idea.
as I don't want it to work continuously
Then do not "make server call whenever device screen is turned ON". Find some other solution for whatever business problem you have that you are trying to solve this way.
I use AlarmManager to issue local notifications to user. But if I kill my application using Settings->Apps->Stop, alarm manager seems to be destroyed and all the notification icons disappears from status bar.
It it normal? The idea of local notifications is to persuade user to start my great app if it's closed. And it seems odd for me that they are being wiped out if I kill the app.
If you KILL your application you also kill the AlarmManager.
There is nothing odd about it. You close the app by pressing the home button, not by killing it via the settings.
Use service to set AlarmManager and notification.
Also keep in mind that once device is restarted Alarm is cancelled.
So you will need to set broadcast receiver.
look at this Click here
I had a few problems with my alarm that are in a another thread here if anyone could help but anyway here is a new question. If I set an alarm using my app, say for 5 minutes from now, and then close the app, how would I code it so that my app activity comes back to the front?
This is basically the same as the clock app already on most android phones. I'm doing this to allow the user to stop the alarm. Would I be right in saying that I would have to modify my existing code to, when the alarm is run, launch a new intent to bring the activity to the front? Or can I simplify this and only have an alertdialog or something open instead of opening the entire app?
Any links would be appreciated
Thanks
Don't move your activity to the front automatically. It's as annoying as a pop-up ad! Do you really want to try to interrupt the user who's trying to look up a phone number?
Instead, use a Service. When you want to tell the user something, post a status bar notification. You can set up the notification to bring up an Activity when the notification is clicked.
Most alarms are implemented in a Service.
Have you looked into the AlarmManager? http://developer.android.com/reference/android/app/AlarmManager.html. I've used it in the future to fire Intents for Notifications. The Notification can then open an Activity for the user when they select the Notification from the Android Notification Bar.