アプリに 4 つのボタンがあります。これらのボタンのうち 2 つでは、実行したいアプリがデバイスにあるかどうかを確認する必要があります。存在する場合は実行し、存在しない場合はトーストを表示します。
問題は、トーストを表示するとき、アプリケーションを閉じるときです。startActivity(Intent) でトーストを表示する最良の方法は何ですか???
これはコードです:
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);