我有一个简单的Android应用程序需要在特定条件下启动另一个应用程序,我需要在应用程序启动时检查条件。也就是说,要么继续启动我的应用程序,要么启动另一个应用程序:
if (A == true) {
launch another activity of another app
leave the current app without creating the main activity
} else {
launch the main activity of the current app
}
有谁能告诉我如何处理A ==真实案例?我能够启动另一个应用程序的活动,但我无法打开当前的应用程序,甚至没有打开主要活动。
任何帮助将不胜感激!
答案 0 :(得分:1)
您可以使用以下意图启动其他应用程序
PackageManager pm;
pm = getPackageManager();
// get a list of installed apps.
packages = pm.getInstalledApplications(0);
如果您不知道要启动的应用程序的包名称,请尝试启动
startActivity(new Intent(CurrentActivity.this,MainActivity.class));
传递您要打开的应用的包名称 如果A == true
,您可以使用它否则您可以将MainActivity作为
启动public class Tanks {
private String TankName;
private int TankModel;
private int CrewNumber;
private double Speed;
private int TurretSpeed;
Tanks (String name, int model, int crew, double speed, int turretspeed){
this.TankName = name;
this.TankModel = model;
this.CrewNumber = crew;
this.Speed = speed;
this.TurretSpeed = turretspeed;
}
public static void main(String[] args) {
Tanks merkava = new Tanks ("MERKAVA", 1, 5, 56.64, 67);
Tanks judge = new Tanks ("JUDGE", 2, 6, 66.66, 68);
public double getSpeed() {
return Speed;
}
System.out.println(merkava.TankName+ " "+merkava.TankModel+" "+merkava.CrewNumber+" "+merkava.Speed+" "+merkava.TurretSpeed);
System.out.println(judge.TankName+ " "+judge.TankModel+" "+judge.CrewNumber+" "+judge.Speed+" "+judge.TurretSpeed);
}
}
答案 1 :(得分:0)
如果您想在没有正常IntentFilter的情况下启动其他应用的其他活动,那么最简单的解决方案是:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.anotherapp.package","com.anotherapp.package.MainActivity"));
startActivity(intent);
当然,您需要知道您想要开始的package name
和Activity
名称
至于完成申请电话
finishAndRemoveTask();