1

I am working on an app where I am useing a PackageManager to import all the package names on the device using this code:

protected void onListItemClick(ListView l, View v, int position, long id) {
    ResolveInfo launchable=adapter.getItem(position);
    ActivityInfo activity=launchable.activityInfo;
    ComponentName name=new ComponentName(activity.applicationInfo.packageName,
                                         activity.name);
    Intent i=new Intent(Intent.ACTION_MAIN);


    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
               Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    i.setComponent(name);

    startActivity(i);    
}

This code manage to start the app from a ListView. But I want to send the app details to another class to start it from there instead of starting it from this class. Then I want the result to be saved but changeable by clicking on another app later.

Are there any ways of doing this?

Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70
Magakahn
  • 498
  • 9
  • 31
  • Can you elaborate on why starting an activity like this is not sufficient? Why do you need to start it from another class? – Ted Hopp Mar 12 '12 at 15:34
  • I am making an app where I make a shortcut to the selected app. – Magakahn Mar 12 '12 at 15:36
  • Doesn't this code launch the other app? It still isn't clear what the problem is. – Ted Hopp Mar 12 '12 at 15:41
  • The point is that you do not need to scroll and click on the app, but you only need to press a button witch uses starts an activity that tries to launch the shortcut. – Magakahn Mar 12 '12 at 15:43

2 Answers2

1

If you only want to select the app from the list and start it using a separate button click, then how about storing the activity.applicationInfo.packageName and activity.name to SharedPreferences once list item is selected. In case the user select other item from the list overwrite the SharedPreferences parameters.

When the start button is clicked read these parameters and launch the app.

Rohit
  • 2,132
  • 1
  • 15
  • 24
  • what Sharedpref? [here](http://developer.android.com/guide/topics/data/data-storage.html#pref) – Rohit Mar 17 '12 at 14:45
0

How about binding to a service, sending a message to that service, and the service will start the activity? Or registering a broadcast receiver, sending an intent to that receiver, with the requested application as extra information, and having the broadcast receiver do the work?

Steelight
  • 3,347
  • 1
  • 20
  • 17
  • I found a nice tutorial for you: http://www.vogella.de/articles/AndroidServices/article.html – Steelight Mar 13 '12 at 07:28
  • I am doing something similar HERE!!! http://stackoverflow.com/questions/14571564/android-pendingintent-extras-not-received-by-broadcastreceiver/14612215#14612215 – Etienne Lawlor Jan 31 '13 at 07:47