Первое, у вас должно быть разрешение на задачу
<uses-permission android:name="android.permission.WAKE_LOCK" />
Пример кода
Thread(Runnable {
// a potentially time consuming task
val bitmap = processBitMap("image.png")
imageView.post {
imageView.setImageBitmap(bitmap)
}
}).start()
Также вам нужно
Рекомендую поискать следующий страница
https://developer.android.com/guide/components/processes-and-threads
Обзор услуг
Вот как я это решил.
publi c класс myservices расширяет службу {@Override publi c int onStartCommand (намерение намерения, int флаги, int startId) {Intent notificationIntent = new Intent (this, MainActivity.class); // Чтобы открыть MainActivity onClick PendingIntent pendingIntent = PendingIntent.getActivity (this, 0, notificationIntent, 0);
Intent busy = new Intent(this, InterceptCall.class);
Intent driving = new Intent(this, InterceptCall.class);
Intent meeting = new Intent(this, InterceptCall.class);
busy.putExtra("mode","busy");
driving.putExtra("mode", "driving");
meeting.putExtra("mode", "meeting");
PendingIntent busyIntent = PendingIntent.getBroadcast(this, 1, busy, PendingIntent.FLAG_UPDATE_CURRENT); //For mini icon in notification bar
PendingIntent drivingIntent = PendingIntent.getBroadcast(this, 2, driving, PendingIntent.FLAG_UPDATE_CURRENT); //For mini icon in notification bar
PendingIntent meetingIntent = PendingIntent.getBroadcast(this, 3, meeting, PendingIntent.FLAG_UPDATE_CURRENT); //For mini icon in notification bar
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Smart Mode is on ")
.setContentText("Drag down to display modes.")
.setContentIntent(pendingIntent)
.setColor(Color.MAGENTA)
.setSmallIcon(R.drawable.pingedlogo)
.addAction(R.mipmap.ic_launcher, "Busy", busyIntent)
.addAction(R.mipmap.ic_launcher, "Driving", drivingIntent)
.addAction(R.mipmap.ic_launcher, "Meeting", meetingIntent)
.build();
startForeground(1, notification);
return START_NOT_STICKY;
}