Intent intent1 = new Intent(context, RecipeDetailActivity.class);
Intent intent2 = new Intent(context, RecipeDetailActivity.class);
Intent intent3 = new Intent(context, RecipeDetailActivity.class);
Intent intent4 = new Intent(context, RecipeDetailActivity.class);
intent1.putExtra("id", (long) 1);
intent1.putExtra("name", "Nutella Pie");
intent2.putExtra("id", (long) 2);
intent2.putExtra("name", "Brownies");
intent3.putExtra("id", (long) 3);
intent3.putExtra("name", "Yellow Cake");
intent4.putExtra("id", (long) 4);
intent4.putExtra("name", "Cheesecake");
PendingIntent pendingIntent1 = PendingIntent.getActivity(context, 1, intent1, PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingIntent2 = PendingIntent.getActivity(context, 1, intent2, PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingIntent3 = PendingIntent.getActivity(context, 1, intent3, PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingIntent4 = PendingIntent.getActivity(context, 1, intent4, PendingIntent.FLAG_CANCEL_CURRENT);
views.setOnClickPendingIntent(R.id.tv_recipe1, pendingIntent1);
views.setOnClickPendingIntent(R.id.tv_recipe2, pendingIntent2);
views.setOnClickPendingIntent(R.id.tv_recipe3, pendingIntent3);
views.setOnClickPendingIntent(R.id.tv_recipe4, pendingIntent4);
编辑:我在活动中添加了不同的请求代码并使用了OnNewIntent方法。现在有效。
我在窗口小部件中有4个视图。如果我按下第一个,我应该打开id = 1的活动,但如果是秒,则打开id = 2的活动,依此类推。
views
是RemoteViews
个对象。 RecipeDetailActivity
将根据意图数据(id和名称)显示数据。该活动包含一个片段,在创建时,将数据设置为片段,然后片段将更新其信息异步。
它不起作用,因为点击它们会产生相同的结果(目前在id = 3)。他们不应该互相取消,这样当我打开一个新的时候会给出新的意图(或者开一个全新的活动)吗?