Reputation: 508
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?
Upvotes: 1
Views: 444
Reputation: 2152
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.
Upvotes: 1
Reputation: 3357
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?
Upvotes: 0