0
ちょうどAndroidを理解し始めて、MenuItemでアクティビティを開始する方法にぶつかりました。私はいつMenuItemsのインテントを設定し、アクティビティを開始させるか、またはMenuItemが選択されたときにstartActivityを呼び出さなければならないのだろうかと思います。MenuItemインテントまたはonOptionsItemSelectedのアクティビティを開始するタイミング
// Call this in onOptionsItemSelected when an item is selected;
private void startSomeActivity() {
Uri geoLocation = Uri.parse("geo:0,0?q=someaddress");
Intent intent = new Intent(Intent.ACTION_VIEW, geoLocation);
if (intent.resolveActivity(getPackageManager()) != null)
startActivity(intent);
}
vs
// Call this in onCreateOptionsMenu and set intent of items.
private Intent getSomeIntent() {
Uri geoLocation = Uri.parse("geo:0,0?q=someaddress");
Intent intent = new Intent(Intent.ACTION_VIEW, geoLocation);
if (intent.resolveActivity(getPackageManager()) != null)
return intent;
return null;
}
両方とも同じように動作しているようです。ありがとう。
どちらも同じですが、あなたが望むものを使用でき、魅力的です –