0

Hi guys how to make my apps running in background so that it can receive notification although the apps being cleared by RAM clearing feature in our phone?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
ALSP
  • 92
  • 1
  • 16
  • @BobMalooga do u have any detailed tutorial? once I followed a tutorial but it couldn't work. – ALSP May 09 '16 at 06:21
  • There's a tutorial (with source code) about Scheduling Repeating Alarms on android developers official site. It uses a service. – Phantômaxx May 09 '16 at 06:53
  • @BobMalooga outside the lifetime of your application meaning if my apps is force closed by the system but the alarm will still execute right? – ALSP May 09 '16 at 07:38
  • Not only. If you reboot your device, the service will still run. – Phantômaxx May 09 '16 at 08:05
  • @BobMalooga bro can u help me more on the coding? because i barely understand as i am new to this – ALSP May 11 '16 at 06:52
  • shall I google it for you? `android scheduling repeating alarms` – Phantômaxx May 11 '16 at 06:55
  • @BobMalooga does the 1st solution work? http://stackoverflow.com/questions/4459058/alarm-manager-example – ALSP May 11 '16 at 07:06
  • Didn't try that. I tried the one on the official docs. And it worked. – Phantômaxx May 11 '16 at 07:08
  • @BobMalooga which part of the coding did u use? sorry for interrupting u but this really matter much to me. http://developer.android.com/training/scheduling/alarms.html – ALSP May 11 '16 at 07:11
  • At first, I ran the project. Then I tried to figure out why did it work and how. The service part is what you need. And the Notification part as well. And the Alarms too. In practice, it's nearly ready to use. Just change the small parts you need to and fit it to your existing UI. – Phantômaxx May 11 '16 at 07:14
  • @BobMalooga Kk thx man mind giving me ur email in case of I need ur help on the coding if I face any problem? – ALSP May 11 '16 at 07:20
  • No. It doesn't work like that, here. – Phantômaxx May 11 '16 at 07:22
  • @BobMalooga just implement this if i want it to call evry 15 mins? alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, AlarmManager.INTERVAL_FIFTEEN_MINUTES, AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent); – ALSP May 11 '16 at 07:29
  • Try. I'm not your 24/7 consultant. – Phantômaxx May 11 '16 at 07:33
  • @BobMalooga tried it, it couldnt work... + I m a newbie :( – ALSP May 11 '16 at 07:48
  • Try harder. We've all been newbies. – Phantômaxx May 11 '16 at 07:58
  • @BobMalooga :( I'm in a rush to submit my apps and this problem is my last one – ALSP May 11 '16 at 08:00

2 Answers2

4

Try to read about a services and/or about GCM. For the notifications GCM is a good choice for Android. Useful links: 1): Service 2) GCM(Google Cloud Messaging)

Viktor Dolgalyov
  • 274
  • 2
  • 12
  • last time i tried the GCM but it had error so i changed to firebase notification feature... does Service apply on firebase notification too? – ALSP May 09 '16 at 06:22
  • @AdrianLoh Services just a object which can ran without UI. So, you can use it as you wish. But I doesn't know what kind of problem you had with GCM. Can you describe? GCM is a good feature for an android projects – Viktor Dolgalyov May 10 '16 at 06:15
  • i've forgotten the problem .. wish i could meet u earlier because the notification implementation had wasted my time very much – ALSP May 10 '16 at 14:56
  • bro can u help me more on the coding? because i barely understand as i am new to this – ALSP May 11 '16 at 06:53
  • @AdrianLoh sure, I can help you with it. Just some steps you should learn about GCM implementation: 1)http://developer.android.com/intl/en/guide/components/services.html - tutorial from Google about services 2) https://developers.google.com/cloud-messaging/gcm - read all points about android in this tutorial(Get started->Android and GCM Clients), it very useful. If you still are having troubles with it - contact with me:) – Viktor Dolgalyov May 11 '16 at 08:24
  • i think i dont have enough time to implement the GCM because im in a rush to submit my apps and my firebase notification working quite well. would appreciate much if u could help me on the service part. – ALSP May 11 '16 at 09:33
  • @AdrianLoh ok, what do you want from service? starting with a system start, right? or maybe restart it if system kill it? – Viktor Dolgalyov May 11 '16 at 11:16
  • i want the apps to receive notification but apparently the apps wont when it is force closed. i want the service to run since the phone is on until the phone is off then automatically start after rebooting ... – ALSP May 11 '16 at 14:00
  • even though the apps is close, it still can receive notification using service... this is what i wan :) – ALSP May 11 '16 at 14:04
2

You need a Service to make your app run in background even if the app has been killed. You need a BroadcastReceiver to start the service when the device boots up.

How to implement it?

Hope it helps :)

Ye Min Htut
  • 2,904
  • 15
  • 28