如何使用待定意图启动新活动

Mat*_*hew 18 android android-intent android-pendingintent

任何人都可以说如何使用待定意图启动新活动,并使用待定意图传递值.提前致谢.

小智 27

Intent intent = new Intent(getApplicationContext(), ActivityToLaunch.class);
intent.putExtra(<oneOfThePutExtraFunctions>);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
Run Code Online (Sandbox Code Playgroud)

您可以使用以下各种Intent.PutExtra()函数之一将额外数据添加到Intent中:http://developer.android.com/reference/android/content/Intent.html

然后,当您准备好启动PendingIntent时,请使用位于以下位置的Send()函数之一:http://developer.android.com/reference/android/app/PendingIntent.html

  • `PendingIntent.getActivity` 的文档说“请注意,该活动将在现有活动的上下文之外启动,因此您必须在 Intent 中使用 Intent.FLAG_ACTIVITY_NEW_TASK 启动标志”。所以你可能应该做“intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);”。 (3认同)