How can I start a service in Activity?
I tried to call:
Notification notification = new Notification(R.drawable.ic_launcher, getText(R.string.app_name),System.currentTimeMillis());
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, getText(R.string.app_name),getText(R.string.app_name), pendingIntent);
startForeground(1, notification);
However, it "Cannot resolve method 'startforeground(int, android.app.Notification)'"
What do I do to call startForeground? I tried getApplicationContext() to no avail.
How can I start a service in Activity?
Call startService()
.
However, it "Cannot resolve method 'startforeground(int, android.app.Notification)'"
startForeground()
is a method on Service
. Your Service
will need to call startForegrond()
upon itself (e.g., in the service's onCreate()
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With