【发布时间】:2012-12-04 15:09:50
【问题描述】:
我的应用程序中有 4 个按钮,在其中 2 个按钮中,我需要检查我要运行的应用程序是否在我的设备中。如果存在,则运行,否则,显示敬酒。
问题是当我展示祝酒词时,应用程序关闭。在 startActivity(Intent) 中显示 Toast 的最佳方式是什么???
这是代码:
public void onClick(View v) {
Intent LaunchIntent = null;
boolean isTouch = isAppInstalled("com.enflick.android.ping");
boolean isWpress = isAppInstalled("org.wordpress.android");
switch (v.getId()) {
case (R.id.botonPortafoli):
LaunchIntent = new Intent(this, PortafoliActivity.class);
break;
case (R.id.botonSocial):
LaunchIntent = new Intent(this, SocialActivity.class);
break;
case (R.id.botonTouch):
if (isTouch) {
LaunchIntent = getPackageManager().getLaunchIntentForPackage(
"com.enflick.android.ping");
} else {
Toast.makeText(this, R.string.no_inst, Toast.LENGTH_LONG)
.show();
break;
}
break;
case (R.id.botonWpress):
if (isWpress) {
LaunchIntent = getPackageManager().getLaunchIntentForPackage(
"org.wordpress.android");
break;
} else {
Toast.makeText(this, R.string.no_inst, Toast.LENGTH_LONG)
.show();
break;
}
}
startActivity(LaunchIntent);
【问题讨论】:
-
应用中断是什么意思? LogCat 说什么?
-
您是否尝试逐行调试以查看其中断的位置?
-
如何在eclipse中逐行调试?我可能会在所有行中都添加检查点??
-
我的第一次尝试是将捕获异常
PackageManager.NameNotFoundException更改为Exception,并确保在未安装应用程序时该方法不返回 true。 -
你只需要左键单击(可能是双击)你想要破解代码的行的左边,你可能需要设置一个属性,比如 debugable 或者我不记得的东西,但我认为 eclipse 会为你做这件事,只是要求去做。