4
4
import android .app .NotificationChannel ;
5
5
import android .app .NotificationManager ;
6
6
import android .app .PendingIntent ;
7
+ import android .content .Context ;
7
8
import android .content .Intent ;
8
9
import android .net .Uri ;
9
10
import android .os .Build ;
@@ -24,7 +25,7 @@ final public class RNBackgroundActionsTask extends HeadlessJsTaskService {
24
25
private static final String CHANNEL_ID = "RN_BACKGROUND_ACTIONS_CHANNEL" ;
25
26
26
27
@ NonNull
27
- public static Notification buildNotification (@ NonNull final ReactContext context , @ NonNull final BackgroundTaskOptions bgOptions ) {
28
+ public static Notification buildNotification (@ NonNull Context context , @ NonNull final BackgroundTaskOptions bgOptions ) {
28
29
// Get info
29
30
final String taskTitle = bgOptions .getTaskTitle ();
30
31
final String taskDesc = bgOptions .getTaskDesc ();
@@ -35,7 +36,8 @@ public static Notification buildNotification(@NonNull final ReactContext context
35
36
if (linkingURI != null ) {
36
37
notificationIntent = new Intent (Intent .ACTION_VIEW , Uri .parse (linkingURI ));
37
38
} else {
38
- notificationIntent = new Intent (context , context .getCurrentActivity ().getClass ());
39
+ //as RN works on single activity architecture - we don't need to find current activity on behalf of react context
40
+ notificationIntent = new Intent (Intent .ACTION_MAIN ).addCategory (Intent .CATEGORY_LAUNCHER );
39
41
}
40
42
final PendingIntent contentIntent = PendingIntent .getActivity (context , 0 , notificationIntent , PendingIntent .FLAG_UPDATE_CURRENT );
41
43
final NotificationCompat .Builder builder = new NotificationCompat .Builder (context , CHANNEL_ID )
@@ -54,7 +56,6 @@ public static Notification buildNotification(@NonNull final ReactContext context
54
56
final boolean progressIndeterminate = progressBarBundle .getBoolean ("indeterminate" );
55
57
builder .setProgress (progressMax , progressCurrent , progressIndeterminate );
56
58
}
57
-
58
59
return builder .build ();
59
60
}
60
61
@@ -77,7 +78,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
77
78
final BackgroundTaskOptions bgOptions = new BackgroundTaskOptions (extras );
78
79
createNotificationChannel (bgOptions .getTaskTitle (), bgOptions .getTaskDesc ()); // Necessary creating channel for API 26+
79
80
// Create the notification
80
- final Notification notification = buildNotification (getReactNativeHost (). getReactInstanceManager (). getCurrentReactContext () , bgOptions );
81
+ final Notification notification = buildNotification (this , bgOptions );
81
82
startForeground (SERVICE_NOTIFICATION_ID , notification );
82
83
return super .onStartCommand (intent , flags , startId );
83
84
}
0 commit comments