1

I am new to android. I am making an alarm clock. Its working perfectly until the user clears the app from the RAM. On searching, I found that broadcast receivers don't work if the app is cleared from the RAM. So, what exactly should I do? Will sending the broadcast from a service help? Also if you have a link to a good tutorial to Services in android, pls do share. Also let me know if there is some other way to solve my problem.

Priyanshu Goyal
  • 332
  • 4
  • 17

4 Answers4

2

In Xiaomi devices, you just have to add your app to Autostart list, to do so, follow these simple steps given below:

  • Open Security app on your phone.

  • Tap on Permissions, it'll show you two options: Autostart and Permissions

  • Tap on Autostart, it'll show you list of apps with on or off toggle buttons.

  • Turn on toggle of your app, you're done!

zeeali
  • 1,524
  • 20
  • 31
  • It worked! but whenever i restart the phone, it agains takes away the autostart permission from the app. How to give it the permission permanently? – Priyanshu Goyal Apr 22 '16 at 16:30
  • I checked it on my Xiaomi Redmi 1s, it doesn't take away the permission, it's still there in autostart list. You'll have to manage the restart using a boot broadcast receiver. – zeeali Apr 23 '16 at 05:17
  • @Sidhartha We cannot automate this workaround, it is device specific settings. You must guide your app users what to do (just like permissions) to get your app running well in their devices. – zeeali Jul 11 '17 at 06:42
  • @zeeali other application like alarm is working without this kind of setup ,they would be adding some permission !! – Sidhartha Jul 11 '17 at 06:52
0

You can register broadcast receivers either inside the activity at runtime or in the manifest. You want to adopt the latter approach

Bruno Carrier
  • 530
  • 5
  • 8
0

In the past I have similar problems with AlarmManager, AlarmReceivers and this kind of things. There are some tips that can help you in your code:

  1. Make sure that you are scheduling your alarm correctly.
  2. Make sure that you are setting the propers permissions on the manifest.
  3. Take care if the device is locked or it was rebooted.

There is a quite useful tutorial that helps me to control and make a "Hello World!" example with AlarmManager: AlarmManager Repeating Example

Note: In API 19 and higher, the method setRepeating is not exactly (maybe the alarm triggers at 10:00 or at 10:15), so you must use setExact.

Hope it helps!

David Corral
  • 4,085
  • 3
  • 26
  • 34
  • The alarm is working perfectly until n unless the user explicitly clears it from the ram. So, I assume that there needs to be a service that is to be used so that somehow the receiver keeps working in the background? – Priyanshu Goyal Apr 21 '16 at 18:02
0

You can register broadcast receiver in two ways

1. From your activity.

2. From your manifest.

if you registered broadcast throught activity, It wont receive after your activity is destroyed, So thats is where we register BroadcastReceiver in manifest.

This link will help you BroadcastReceiver

Arun Shankar
  • 612
  • 1
  • 5
  • 16
  • Yes, I had registered it in manifest. The alarm doesnt work if the application is cleared from the RAM by the user from the multitasking window. If the alarm is present on the RAM, it works perfectly well. – Priyanshu Goyal Apr 21 '16 at 18:04