How to Call Activity in Android Service

Asked 2 years ago, Updated 2 years ago, 138 views

public class LocationService extends Service {

@Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        startActivity(new Intent(this, activity.class));
    }
}

We created a service that runs in the activity like this.

I'd like to call the activity if the conditions are met.

startService(new Intent(WozzonActivity.this, LocationService.class)); Activities cannot be called in the Location Service.

How do I get the context I'm currently working on in the service class?

android android-activity service

2022-09-22 21:41

1 Answers

in the class of service.
Intent dialogIntent = new Intent(this, MyActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);

This is how you do it.


2022-09-22 21:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.