Reputation: 49
I am developing an Android application with Jetpack Compose. My application will be a reminder application. Since I want the application to be available offline, I store the data in the room database. But the problem is that I want to send a notification to the application for reminder, of course, the information about the time to send the notification is kept in the room database. That's why I'm having trouble sending notifications when the app is closed. What do you think I should do?
I want to send notifications even if the application is closed. I think the problem is that I call the information from the database with the suspend function and I can use it with Coroutines. Because Coroutines work with Ui, that is, it does not work without starting the application.
Upvotes: 1
Views: 37
Reputation: 67
you should add this permission to your manifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
and in application tag :
<receiver
android:name="AutoStart"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
and this is AutoStart class
public class AutoStart extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent intentService = new Intent(context, Service.class);
context.startForegroundService(intentService);
}
}
this configuration make your app autoStart when device turn on . and then log your service to make sure your app service start properly . some feautres use context not working when activities not running like shared preferences . you should use getApplicationContext() method instead
Upvotes: 0