How to send local notification android when app is closed? - android

I'd like to know if it's possible to send a local notification to the device when the app have been opened then closed.
It works already when my app is opened and when it's in the background.
Thanks
Edit : I think i wasn't clear enough:
I want to send a local notification at a given time even if the app is not running at that time.

By "Local Notification" i mean a Notification (android class) created in my app and send by using an AlarmManager and a BroadcastReceiver.
closed -> killed the process of my app
Most means of "killed the process of [your] app" will leave your alarms intact, and so whatever you have scheduled will remain scheduled and keep being invoked as you set up.
I want to send a local notification at a given time even if the app is not running at that time.
Again, AlarmManager is not dependent upon your process being around, so long as it can invoke the PendingIntent that you supply. So long as the BroadcastReceiver you are using is registered in the manifest (and not via registerReceiver()), it should work fine.
If the user force-stops your app -- usually via the Settings app -- then not only will your alarms not be invoked, but your code will never run again, until something explicitly starts up your app (usually the user tapping on your icon in the launcher). There is nothing that you can do about this.
it's hard to explain things when you do understand fully and when english is not your native language
There are many Android developer support sites, offering a variety of languages.

you need to create a service, http://developer.android.com/guide/components/services.html

Related

Show notification icon on status bar with React Native when app is not running on Android

I have a situation on my React Native app, where user can start a timer and isRunning and startTime states are stored in the app so that it can display current running time when the app is in foreground even though the user quits the application at some point and opens it again.
Is there a way to show notification icon on status bar when the timer is running, but user has quit the application to indicate that the timer is currently "running" (actually it is not doing any operations on background) on background?
I have encountered some apps that display a silent notification that is not directly closable after I have quit the app, but I haven't seen a situation where status bar notification is present (together with notification) until some condition is met after the app is quit by the user.
Is there a way to achieve this? I am using react-native-push-notification and Firebase to push notifications in my app overall.
React-Native manages only Active and Background/Inactive/Foreground state. When user kill the app. JS engine shuts down.
All you can use is Local Notification and Scheduled Notification. I also have one app in which user set a reminder time. And notification invoke at that specified time.
Using Firebase I guess you need to call api after some specific interval for push notification from server side.
I am not an expert in background services or android development but here is my thought... I believe you could dig in and write some java android code for a background unstoppable service (persistent on app close or background states). You can do this by creating a bridge and using native modules to manage your background services. I came across a great resource on medium that details the process of creating a background service, a broadcast receiver and maintaining Headless instance even when the app is closed or the device restarts.Hope that helps you achieve your goal.
Edit
This ready made package will help you with better. Check it out. You actually don't have to write native android java code at all.

Get Notification from Android OS at a specific time even if application is killed

I want to get a notification at a specific time, say at 8am and 8pm even if my application is not running.
Application must receive notification even if OS kill my application from background due to low memory.
I don't want to use Push Notification as it will require a dedicated server which I don't have.
Is there any functionality like iOS has, where OS send notification or Silent message to application irrespective if application is in memory or it is closed/Forced stop by OS/user.
You can use AlarmManager. It has these characteristics:
... operate outside of your application, so you can use them to trigger events or actions even when your app is not running, and even if the device itself is asleep. Link to documentation

How do Android applications such as Facebook Messenger and Llama stay running in the background from boot time?

I'm developing an application that uses a Bound Service to query information from a server and provide notifications when conditions are met. At the moment, the user must execute the application from their home screen in order to begin receiving updates. But, for example, applications like the Facebook Messenger and Llama run from the moment the phone starts in the background. How do I achieve similar functionality for my long-term application? Also, even when my application is run from the home screen, it will still ocationally quit in the background from what I assume to be the system quitting the application for additional resources. Even though my application is made to restore the service when it begins again, it never seems to restart after it quits (usually after 3 to 4 hours of background activity).
Thanks for your help.
You can register a BroadcastReceiver for the ACTION_BOOT_COMPLETED Intent to detect when the device is booted. This requires the RECEIVE_BOOT_COMPLETED permission.
Instead of using a bound Service you can use a started sticky Service. However, depending on what exactly you want to do, you might want to check if AlarmManager suits your requirements better (maybe in combination with an IntentService, cf. cwac-wakeful).

Notifications on an app after it is shut down with the 4.0 android task manager?

I'm using C2DM in my application, and I have a receiver, which sends data to a class in the application. The class creates a notification and notifies the notification manager to post it.
The problem is that this does not work when the app is forced close manually through the settings, as this also (apparently) shuts off the broadcast receiver.
What I get though is that when an app is shut off with android 4.0's new task manager (the one thats similar to 3.0 but a user can also swipe an app to the left or right to shut it off) it behaves differently: the broadcast receiver is still working, as I get the intent from the C2DM message, but for some reason my phone still plays the notification noise, whilst no notification appears in the tray.
I can't figure out what's happening, because there is no way for the sound to play without the notification to appear, as the sound is attached to the notification and plays when it's posted, no other way. But no notification appears.
Any insight on why this might be happening would be awesome, or what the new 4.0 task manager actually does to apps when you swipe them off the list.
Thanks.
Figured it out, the broadcast receiver was still responding but just failing because it was retrieving things from a class that was part of the main app and was now dead, so now the things it needs are stored in sharedprefs, and retrieved before the notification gets sent.
So to answer the question, no swiping an app from the task manager in 4.0 does not "force kill" the app in the same was as the force kill button in the applications menu in settings. It does kill off the app in such that next time you open it, all the activities restart from scratch, just like if you had been in the last remaining activity and pressed back, hereby calling finish() on the last alive task and shutting down the app. broadcast revivers (and services i assume) still are running afterwards.

Scheduling Android Service to Run & Restart if Closed

I'm trying to implement an App that will perform a periodic sync w/ server, lets say ever 30 min. I have been successfully able to implement this using a Receiver & Service triggered via AlarmManager, however the downside is that if the App is closed through TaskMgr the alarm dies with it.
I understand that this is expected behavior for Android OS, however I noticed that some Apps like Facebook have a service that starts back up after a short timeout even if the Facebook App was closed in TaskMgr. I monitored this and see the service disappear and re-start after about a minute or so. There's a number of Apps that behave in similar fashion (Twitter, Dictionary, ReadItLater, etc)
I would like to reproduce this behavior. This way even if the user closes my App in TaskMgr by mistake they can still have periodic sync run in the background.
Thanks in advance.
There should be an inbound process associated with the service if it needs to be restarted even after cloasing using task killers.YOu can achieve this by displaying an ongoing notification at notification area as long as service exists and by launching service via startForeground()
http://www.androiddiscuss.com/1-android-discuss/91804.html
please check the link

Categories

Resources