所以我试图通过按一个小部件来开始一个活动.我一直遇到错误“对于照片类型,未定义方法startActivity(Intent)”,非常感谢您的帮助!我的课程代码如下:
package com.natehoch96.Widgets.iOS;import androID.appWidget.@R_502_1061@;import androID.content.Intent;public class Photos extends @R_502_1061@ { Intent myIntent = new Intent(androID.provIDer.Settings.ACTION_SETTINGS); {startActivity(myIntent); }}
解决方法:
您需要在@R_502_1061@类中实现onUpdate()和onReceive()方法,如下所示:
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()方法以接收待处理的意图并开始相关的活动:
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); }}
总结 以上是内存溢出为你收集整理的android-方法startActivity(Intent)未定义类型?全部内容,希望文章能够帮你解决android-方法startActivity(Intent)未定义类型?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)