dlu*_*cci 4 android android-studio
我正在 android studio 0.89 中编写一个面向 API 级别 20 的小部件。在我的 AppWidgetProvider 中,我试图创建一个挂起的意图来响应按下的按钮。我的问题是 IDE 无法识别 PendingIntent 中的任何方法。这是我的代码:
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widdlewidget_layout);
Intent wifiIntent = new Intent(context, WiddleWidget.class);
wifiIntent.setAction(WIFI_ACTION);
ctx = context;
PendingIntent pi = new PendingIntent.getBroadcast(context, 0 , wifiIntent, 0);
}
Run Code Online (Sandbox Code Playgroud)
问题在于我创建 pi 的地方。任何帮助表示赞赏。
干杯
小错误
只需从这里删除新关键字
PendingIntent pi = PendingIntent.getBroadcast(context, 0 , wifiIntent, 0);
Run Code Online (Sandbox Code Playgroud)
解释 :
您不能在PendingIntent 中使用new关键字,因为它是一个单例类。单例意味着这些类带有私有构造函数。
| 归档时间: |
|
| 查看次数: |
1455 次 |
| 最近记录: |