我想在用户点击小部件中的产品
时启动DetailActivty我使用的代码就是这个。设置PendingIntentTemplete
ProductWigetProvider.class
Intent detailActivityIntent = new Intent(context, ProductDetailActivity.class);
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
taskStackBuilder.addParentStack(ProductDetailActivity.class);
taskStackBuilder.addNextIntent(detailActivityIntent);
PendingIntent pendingIntent = taskStackBuilder.getPendingIntent( 1,PendingIntent.FLAG_UPDATE_CURRENT);
views.setPendingIntentTemplate(R.id.widget_list_view,pendingIntent);
和此代码设置fillInIntent 的 ProductRemoteViewFactory.class
Intent fillInIntent = new Intent();
fillInIntent.setData(uri);
views.setOnClickFillInIntent(R.id.widget_list_item_container,fillInIntent);
我的清单是
<activity
android:name=".ui.EditProductActivity"
android:label="@string/title_activity_add_new_item"
android:parentActivityName=".ui.ProductDetailActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.dharmaraj.inventorymanager.ui.ProductDetailActivity" />
</activity>
当我从widge中打开DetailActivty,然后按回来时,应用程序关闭而不打开主CatalogActivty。
答案 0 :(得分:1)
尝试类似于以下代码的内容(用于从通知中启动详细信息活动):
Intent backIntent = new Intent(context, MainActivity.class);
backIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent action = new Intent(context, DetailActivity.class);
PendingIntent operation =
PendingIntent.getActivities(this, 0, new Intent[] {backIntent, action}, PendingIntent.FLAG_CANCEL_CURRENT);
希望有所帮助!