I have a reminder app that sends a notification according to the time of the item in the listview, the problem is that whenever my phone is rebooted or the app is killed, the app doesn't send any notification.
Note: The app is offline and local, it doesn't use internet connection, I don't use FCM or and online services for this app.
Thank you so much for your time.
Update:
I'm using a thread that searches for data in the local database, If there are any changes in time in the database compared to the current time, the notification should show, but the notification only shows when the app is running, but when the app is killed it doesn't show.
The app needs to run on android 5+,
Asked
Active
Viewed 125 times
1

JustBeginner
- 319
- 1
- 2
- 8
-
Can you share some code? – Sujal Kumar Jan 06 '22 at 13:25
2 Answers
0
You can use Broadcast receiver in order to be notified when Boot Completes. And again start the required services of your app.
For reference, have a look here.

Kamal Nayan
- 1,635
- 1
- 5
- 19
-
I tried the Broadcast receiver but It didn't work. I'm trying to run my app on android 5 and up (android 5,6,7,8,9,10....) – JustBeginner Jan 07 '22 at 01:10
0
This is because when you are killing the app, the onDestroy
method gets called. When it's killed, you app is not doing anything. For this you would need a broadcast receiver.
How to implement broadcast receiver?
Create a java class named
TimeBradcastReceiver.java
.Paste this code in the class
public class TimeBradcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String dateString = Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE); String hourString = Calendar.getInstance().get(Calendar.HOUR); String minutesString = Calendar.getInstance().get(Calendar.MINUTE; Log.d("MyBradcastReceiver","i have recieved - " + dateString); } }
Once you have implemented this code, you need to add this to you manifest inside the
application
tag.<receiver android:name="com.chatverse.free.TimeBroadcastReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action.TIME_TICK"/> </intent-filter> </receiver>
Add this code to your activity which opens the first.
IntentFilter mTime = new IntentFilter(Intent.ACTION_TIME_TICK); registerReceiver(new TimeBradcastReceiver(), mTime);
Now you can do the comparison of the dates and hours and show the notification.
Note - This receiver will update only when a minute has changed.

Sambhav Khandelwal
- 3,585
- 2
- 7
- 38
-
adding in `Mark it as an accepted answer if it helps as it may help others too!` removes value from the answer itself, because it would be irrelevant for everyone reading it in future, but you're welcome to remind OP to accept an answer if they're happy with it with comments – a_local_nobody Jan 06 '22 at 14:19
-
I tried the AlarmManager but It didn't work. I'm trying to run my app on android 5 and up (android 5,6,7,8,9,10....) – JustBeginner Jan 07 '22 at 01:10
-
-
I tried it, it sends me the time in log every minute, but that only works when the app is running, but if I killed the app, it doesn't work anymore, I added a toast to see it visually, but with no success. – JustBeginner Jan 07 '22 at 18:50
-