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

    2. <i id='i9XiP'><tr id='i9XiP'><dt id='i9XiP'><q id='i9XiP'><span id='i9XiP'><b id='i9XiP'><form id='i9XiP'><ins id='i9XiP'></ins><ul id='i9XiP'></ul><sub id='i9XiP'></sub></form><legend id='i9XiP'></legend><bdo id='i9XiP'><pre id='i9XiP'><center id='i9XiP'></center></pre></bdo></b><th id='i9XiP'></th></span></q></dt></tr></i><div id='i9XiP'><tfoot id='i9XiP'></tfoot><dl id='i9XiP'><fieldset id='i9XiP'></fieldset></dl></div>
    3. <small id='i9XiP'></small><noframes id='i9XiP'>

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

      该类型的方法 startActivity(Intent) 未定义?

      时间:2023-09-09
        <i id='wdiGm'><tr id='wdiGm'><dt id='wdiGm'><q id='wdiGm'><span id='wdiGm'><b id='wdiGm'><form id='wdiGm'><ins id='wdiGm'></ins><ul id='wdiGm'></ul><sub id='wdiGm'></sub></form><legend id='wdiGm'></legend><bdo id='wdiGm'><pre id='wdiGm'><center id='wdiGm'></center></pre></bdo></b><th id='wdiGm'></th></span></q></dt></tr></i><div id='wdiGm'><tfoot id='wdiGm'></tfoot><dl id='wdiGm'><fieldset id='wdiGm'></fieldset></dl></div>
        <tfoot id='wdiGm'></tfoot>

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

            <legend id='wdiGm'><style id='wdiGm'><dir id='wdiGm'><q id='wdiGm'></q></dir></style></legend>

                <tbody id='wdiGm'></tbody>
                <bdo id='wdiGm'></bdo><ul id='wdiGm'></ul>

              • 本文介绍了该类型的方法 startActivity(Intent) 未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                所以我试图通过按下一个小部件来启动一个活动.我一直遇到错误对于照片类型未定义方法 startActivity(Intent)",非常感谢任何帮助!我的课程代码如下:

                So im trying to start an activity by pressing a widget. I keep running into the error "The method startActivity(Intent) is undefined for the type Photos" any help is much appreciated! My class code is below:

                package com.natehoch96.widgets.iOS;
                
                import android.appwidget.AppWidgetProvider;
                import android.content.Intent;
                
                
                public class Photos extends AppWidgetProvider {
                
                    Intent myIntent = new Intent(android.provider.Settings.ACTION_SETTINGS);
                    {startActivity(myIntent); }
                
                }
                

                推荐答案

                您需要在 AppWidgetProvider 类中实现 onUpdate() 和 onReceive() 方法,如下所示:

                You need to implement the onUpdate() and onReceive() methods in your AppWidgetProvider class, something like this:

                public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
                    int[] appWidgetIds) {
                    final int N = appWidgetIds.length;
                    for (int i=0; i<N; i++) {
                        int appWidgetId = appWidgetIds[i];
                
                        //Get the views for your widget layout
                        RemoteViews views = new RemoteViews(context.getPackageName(), 
                            R.layout.my_widget);
                
                        //Create a pending intent for a widget click
                        Intent intent = new Intent(context, Photos.class);
                        intent.setAction("PhotosAction");
                        PendingIntent pendingIntent = 
                            PendintIntent.getBroadcast(context, 0, intent, 0);
                        views.setOnClickPendingIntent(R.id.widget_click_view, pendingIntent);
                
                        appWidgetManager.updateAddWidget(appWidgetId, views);
                    }
                }
                

                然后编写你的 onReceive() 方法来接收待处理的意图并启动相关活动:

                Then write your onReceive() method to receive the pending intent and start the relevant activity:

                public void onReceive(Context context, Intent intent) {
                    super.onReceive(context, intent);
                
                    if (intent.getAction().equals("PhotosAction") {
                        //Received photos action action, start your target activity
                        Intent i = new Intent(android.provider.Settings.ACTION_SETTINGS);
                        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(i);
                    }
                }
                

                这篇关于该类型的方法 startActivity(Intent) 未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 Android 主屏幕小部件中使用 SpannableString? 下一篇:Android 小部件未更新 - 小部件 ID 不正确

                相关文章

                • <bdo id='zvm2j'></bdo><ul id='zvm2j'></ul>

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

                    <tfoot id='zvm2j'></tfoot>

                  1. <small id='zvm2j'></small><noframes id='zvm2j'>