After starting default calculator and hitting back navigation, the user is returned to a different activity rather than the calling activity. When the user clicks the calculator button, the devices default calculator opens. Upon invoking onBackPressed, the user is returned to a different activity within the app that they should not be going to. How can I make sure that the user is returned to the calling activity? Here's my code and what I have tried:
public static void openByName(Context context, String name){
ArrayList<HashMap<String,Object>> items =new ArrayList<HashMap<String,Object>>();
final PackageManager pm = context.getPackageManager();
List<PackageInfo> packs = pm.getInstalledPackages(0);
for (PackageInfo pi : packs) {
if( pi.packageName.toLowerCase().contains(name)){
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("appName", pi.applicationInfo.loadLabel(pm));
map.put("packageName", pi.packageName);
items.add(map);
}
}
if(items.size()>=1){
String packageName = (String) items.get(0).get("packageName");
Log.d(TAG, "PackageName: " + packageName);
Intent i = pm.getLaunchIntentForPackage(packageName);
if (i != null)
context.startActivity(i);
}
else{
// Application not found
Toaster.make(context, name + " not found");
}
}
After different method attempts, I had to use this way because it otherwise wouldn't work on some devices.