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
Related
I am new to coding. I am using Android Studio with Java. I spent the last 3 hours looking for how to set up a notification display at the top when the user leaves the app so they can always click on the notification when they want to return to the app but I couldn't find anything with that action I need.
The app tracks the users GPS and I want them to be able to always be aware that when the app is running it will continue to track their GPS. So my idea is to have a notification window pop up whenever they leave the app so they can be aware the app is running in the background.
Any help will be much appreciated! I am building this app on my own as a passion project and I am taking the Udacity Google Android course. I finished the course early and working on this app for fun. We didn't learn about Notifications or GPS tracking but I am doing my best to learn new things. Thank you for your patience and help!
My app code is here for easy viewing:
https://github.com/PoetryHorizon/eloteroMan2
Use a foreground Service. For any background logic, you should be using a Service anyway, and in Android Oreo and above, you're required to have it be a foreground Service, meaning it posts a Notification.
You can then add a PendingIntent to that notification set to reopen your app. See Android's Notification documentation on how to set a PendingIntent. You'll want to use PendingIntent.getActivity(), where the Intent you pass is new Intent(someContext, YourActivity.class).
I'd like to know if it is possible to create a notification or toast/alert from my app when another app is opened. For example, my app Foo will create a notification if Facebook is opened.
Edit: What I actually want is to inform the user that my app is running in the background when the default camera app opens/running. My app will modify photos taken with the default camera app when it is running in the background and I want to inform the user that it will do so. Is this possible?
Basically what you want is a push notification. Please go through following tuts to help yourself:
https://neurobin.org/docs/android/push-notification-gcm-client-server/
https://developers.google.com/cloud-messaging/android/start
Yeah, you can take a look at this and then schedule an alarm using some background running process that looks for Facebook being running.
One way is to use AlarmManager to check running apps every 5-10 mins and you can generate a notification if your condition is met.
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 have a very hard time to finding real solution.I searched a lot but I cant find any good solution for my problem.
I want to perform some action when user click on notification.So I have to check whether application in background or foreground. If it is in foreground then which activity is running ? There must be simple way to find this.
Please Guide me on this.Any help will be appreciated.
You should listen in two places of your application:
In your activity to show the alert.
In your service to show the notification check if activity is running using one of following solutions.
You have severals answers there summarizing the solutions:
Android: how do I check if activity is running?
Checking if an Android application is running in the background
Because If application is in background then show notification otherwise show alert.
Then you do not care "whether application in background or foreground" or "If it is in foreground then which activity is running".
You simply care that, when the event occurs, either the foreground UI handles it (if there is a foreground UI), or else you show a Notification.
One approach is to use an ordered broadcast, as I blogged about a couple of years ago. Here is a sample app that demonstrates this. Basically, the service(?) sends an ordered broadcast. The UI has a high-priority receiver for that broadcast when it is in the foreground, and it aborts the broadcast and consume the event. You also have a low-priority receiver, one that will only get control if the UI did not consume the event, that will display the Notification.
I am new to android and I was trying out an app as "Scheduled messaging".
Scenario:
Suppose you want to send some message to your friend at 6PM.
Then you can just make an entry and message will be sent automatically at that time.
But now where I am stuck up is that the application must run always even if user tries to close it because else message wont be sent.
Can anyone please give me a small demo for this.
thanks!!!
You could run your task as a service. Or preferably use an alarm. Have a look at the AlarmManager System Service