本文介绍了该方法startActivity(意向)是未定义的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我尝试启动由pressing微件的活动。我一直运行到错误的方法startActivity(意向)是未定义的类型的照片任何帮助是非常AP preciated!我的类code是如下:
包com.natehoch96.widgets.iOS;
进口android.appwidget.AppWidgetProvider;
进口android.content.Intent;
公共类图片扩展AppWidgetProvider {
意图myIntent =新的意图(android.provider.Settings.ACTION_SETTINGS);
{startActivity(myIntent); }
}
解决方案
您需要实现的OnUpdate()和的onReceive()在你的AppWidgetProvider类的方法,是这样的:
公共无效的OnUpdate(上下文的背景下,AppWidgetManager appWidgetManager,
INT [] appWidgetIds){
最终诠释N = appWidgetIds.length;
的for(int i = 0; I&n种;我++){
INT appWidgetId = appWidgetIds [I]
//获取你的部件布局的意见
RemoteViews意见=新RemoteViews(context.getPackageName()
R.layout.my_widget);
//创建一个悬而未决的意图的插件点击
意向意图=新的意图(背景下,Photos.class);
intent.setAction(PhotosAction);
PendingIntent pendingIntent =
PendintIntent.getBroadcast(上下文,0,意图,0);
views.setOnClickPendingIntent(R.id.widget_click_view,pendingIntent);
appWidgetManager.updateAddWidget(appWidgetId,意见);
}
}
然后再编写的onReceive()方法来接收未决的意图,并启动相关活动:
公共无效的onReceive(上下文的背景下,意图意图){
super.onReceive(背景下,意图);
如果(intent.getAction()。等于(PhotosAction){
//收到的照片行动对行动,开始你的目标活动
意图I =新的意图(android.provider.Settings.ACTION_SETTINGS);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(ⅰ);
}
}
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); }
}
解决方案
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);
}
}
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(意向)是未定义的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!