user2603358
user2603358

Reputation: 1

Start an app from a running background service

Just wondering if its possible to launch an install application from a background service. I have the packagename as well.

Upvotes: 0

Views: 357

Answers (4)

Dixit Patel
Dixit Patel

Reputation: 3192

yes you can launch an activity from a service. use this code this is worked for me

Intent mIntent = new Intent(getApplicationContext(), YourActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(mIntent);

don't forget to called mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) otherwise its gives error

Upvotes: 0

Lord Nick
Lord Nick

Reputation: 583

Intent intent= getPackageManager().getLaunchIntentForPackage("com.example.package_name");
startActivity( intent);

For more information you can see package manager and getLaunchIntentForPackage

Upvotes: 0

Nishant Shah
Nishant Shah

Reputation: 1586

An installed application can be invoked using PackageManager class

startActivity(BackgroundService.this.getPackageManager()
                .getLaunchIntentForPackage(packageName)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

Upvotes: 2

Gabe Sechan
Gabe Sechan

Reputation: 93708

Yes, you can launch an activity from a service.

Upvotes: 0

Related Questions