up vote 0 down vote favorite

I have an android application that starts pandora by voice command. It works great, but I want the activity to switch back to my application, leaving pandora running in the background. I'm using this code to launch pandora:

PackageManager pm = getPackageManager()
String packageName = "com.pandora.android";
launchIntent = pm.getLaunchIntentForPackage(packageName);
catch (Exception e1)

Any thoughts?

share|improve this question

1 Answer 1

active oldest votes
up vote 0 down vote

First glance I thought you could use Activity.startActivities, as in:

 final PackageManager pm = getPackageManager();
try {
startActivities(new Intent[] {
} catch (final Exception ignored) {
// Nothing to do
} finally {

But Pandora needs a little time to start playback and in that case, I think you best bet is to set up a NotificationListenerService and wait for Pandora's notification to be posted, which would indicate playback has started, then launch your app.

Here's an example:

public class PandoraNotificationListener extends NotificationListenerService {
public void onNotificationPosted(StatusBarNotification sbn) {
final String packageName = sbn.getPackageName();
if (!TextUtils.isEmpty(packageName) && packageName.equals("com.pandora.android")) {
startActivity(new Intent(this, YourActivity.class)
public void onNotificationRemoved(StatusBarNotification sbn) {
// Nothing to do

In your AndroidManifest

android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
<action android:name="android.service.notification.NotificationListenerService" />

Also, your users will need to enable your app to listen for notifications to be posted under:

  • Settings --> Security --> Notification access

But you can direct your users straight there by using the following Intent:

startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
share|improve this answer

Not the answer you're looking for? Browse other questions tagged android background android-activity pandora or ask your own question.