• <bdo id='24mZz'></bdo><ul id='24mZz'></ul>

      <i id='24mZz'><tr id='24mZz'><dt id='24mZz'><q id='24mZz'><span id='24mZz'><b id='24mZz'><form id='24mZz'><ins id='24mZz'></ins><ul id='24mZz'></ul><sub id='24mZz'></sub></form><legend id='24mZz'></legend><bdo id='24mZz'><pre id='24mZz'><center id='24mZz'></center></pre></bdo></b><th id='24mZz'></th></span></q></dt></tr></i><div id='24mZz'><tfoot id='24mZz'></tfoot><dl id='24mZz'><fieldset id='24mZz'></fieldset></dl></div>

      <small id='24mZz'></small><noframes id='24mZz'>

        <tfoot id='24mZz'></tfoot>

        <legend id='24mZz'><style id='24mZz'><dir id='24mZz'><q id='24mZz'></q></dir></style></legend>

        如何从 Widget 传递数据并打开 Activity?[安卓]

        时间:2023-09-08
          <bdo id='sv7RN'></bdo><ul id='sv7RN'></ul>

              <tbody id='sv7RN'></tbody>

            <small id='sv7RN'></small><noframes id='sv7RN'>

            1. <legend id='sv7RN'><style id='sv7RN'><dir id='sv7RN'><q id='sv7RN'></q></dir></style></legend>

              <i id='sv7RN'><tr id='sv7RN'><dt id='sv7RN'><q id='sv7RN'><span id='sv7RN'><b id='sv7RN'><form id='sv7RN'><ins id='sv7RN'></ins><ul id='sv7RN'></ul><sub id='sv7RN'></sub></form><legend id='sv7RN'></legend><bdo id='sv7RN'><pre id='sv7RN'><center id='sv7RN'></center></pre></bdo></b><th id='sv7RN'></th></span></q></dt></tr></i><div id='sv7RN'><tfoot id='sv7RN'></tfoot><dl id='sv7RN'><fieldset id='sv7RN'></fieldset></dl></div>
                <tfoot id='sv7RN'></tfoot>

                  本文介绍了如何从 Widget 传递数据并打开 Activity?[安卓]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在实现 RemoteViewsFactoryListProvider 类中,我将以下代码放在下面:

                  In my ListProvider class that implements RemoteViewsFactory I have putted the following code below:

                  @Override
                  public RemoteViews getViewAt(int position) {
                      RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.list_row);
                  
                  rv.setTextViewText(R.id.heading, merch_name);
                          rv.setTextViewText(R.id.content, teaser);
                  
                          Bundle extras = new Bundle();
                          extras.putInt(WidgetProvider.EXTRA_ITEM, position);
                          extras.putString(WidgetProvider.MERCHANT_ITEM, mWidgetItems.get(position).merchant_id);
                  
                  
                          Intent fillInIntent = new Intent();
                          fillInIntent.putExtras(extras);
                          rv.setOnClickFillInIntent(R.id.llRow, fillInIntent);
                  
                    return rv;
                  }
                  

                  我将日志放在 WidgetProvideronReceive 中,当我单击它时它具有正确的 ID,但是在打开活动后它没有正确的 ID放入extras.有时它也不会打开我提供的Activity,而只是打开我的MainActivity.当我从 recently open app 中删除我的应用程序,然后使用 widget 时,就会发生这种情况.

                  I put Logs in my onReceive of WidgetProvider it has the correct ID when I clicked, but after opening the activity it doesn't have the correct ID where it is put in extras. There are time as well that it does not open the Activity I provided and just open my MainActivity. This happens when I removed my app from recently open app and then use the widget.

                  这是我的 WidgetProvideronReceive 的代码

                  Here is my code for onReceive in my WidgetProvider

                   public class WidgetProvider extends AppWidgetProvider {
                  
                   public static final String TOAST_ACTION = "my.packagename.TOAST_ACTION";
                  public static final String MERCHANT_ITEM = "my.packagename.MERCHANT_ITEM";
                  
                  @Override
                  public void onReceive(Context context, Intent intent) {
                      AppWidgetManager mgr = AppWidgetManager.getInstance(context);
                  
                      if (intent.getAction().equals(TOAST_ACTION)) {
                          int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                                  AppWidgetManager.INVALID_APPWIDGET_ID);
                  
                          Intent goToDetails = new Intent(context, DetailsActivity.class);
                          goToDetails.putExtra(Constants.MERCHANT_ID, intent.getStringExtra(MERCHANT_ITEM) );
                  
                          goToDetails.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                          context.startActivity(goToDetails);
                  
                        super.onReceive(context, intent);
                  
                      }
                  

                  这就是我在 DetailsActivity 中获取 ID 的方式

                  And this is how I get the ID in my DetailsActivity

                   public class DetailsActivity extends Activity {
                  
                   String merchantID;
                  
                   @Override
                  protected void onCreate(Bundle savedState) {
                  
                   super.onCreate(savedState);
                      setContentView(R.layout.detailsactivity);
                  
                    Bundle extras = getIntent().getExtras();
                      if (extras != null) {
                          merchantID = extras.getString(Constants.MERCHANT_ID);
                      }
                  

                  如何解决这个问题?提前谢谢你.

                  How to solve this? Thank you in advance.

                  推荐答案

                  我在传递数据的 onReceive 中添加了 setData().

                  I added setData() in my onReceive where I pass data.

                   @Override
                  public void onReceive(Context context, Intent intent) {
                   super.onReceive(context, intent);
                  
                      if (intent.getAction().equals(TOAST_ACTION)) {
                      int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                              AppWidgetManager.INVALID_APPWIDGET_ID);
                  
                      Intent goToDetails = new Intent(context, DetailsActivity.class);
                      goToDetails.putExtra(Constants.MERCHANT_ID, intent.getStringExtra(MERCHANT_ITEM) );
                  
                      goToDetails.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                      goToDetails.setData(Uri.parse(goToDetails.toUri(Intent.URI_INTENT_SCHEME)));
                      context.startActivity(goToDetails);
                  
                  
                  
                  }
                  
                  }
                  

                  但是我遇到了崩溃,如果我卸载应用程序然后安装并且没有先打开应用程序然后添加一个 widget 并单击 ListView.

                  But I encounter a crash, if I un-install the app and then install and doesn't open the app first then add a widget and click on the ListView.

                  找出它为什么会因为我的数据库而崩溃,但它仍然不存在.因为我在我的 SplashActivity

                  Found out why it crashes because of my database it still doesn't exist. Because I'm creating my database in my SplashActivity

                  这篇关于如何从 Widget 传递数据并打开 Activity?[安卓]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android:从主屏幕小部件拨打电话 下一篇:Android小部件:如何更改按钮的文本

                  相关文章

                  <i id='NI4Ku'><tr id='NI4Ku'><dt id='NI4Ku'><q id='NI4Ku'><span id='NI4Ku'><b id='NI4Ku'><form id='NI4Ku'><ins id='NI4Ku'></ins><ul id='NI4Ku'></ul><sub id='NI4Ku'></sub></form><legend id='NI4Ku'></legend><bdo id='NI4Ku'><pre id='NI4Ku'><center id='NI4Ku'></center></pre></bdo></b><th id='NI4Ku'></th></span></q></dt></tr></i><div id='NI4Ku'><tfoot id='NI4Ku'></tfoot><dl id='NI4Ku'><fieldset id='NI4Ku'></fieldset></dl></div>

                    <bdo id='NI4Ku'></bdo><ul id='NI4Ku'></ul>

                    <legend id='NI4Ku'><style id='NI4Ku'><dir id='NI4Ku'><q id='NI4Ku'></q></dir></style></legend>
                    1. <small id='NI4Ku'></small><noframes id='NI4Ku'>

                      <tfoot id='NI4Ku'></tfoot>