public class MainActivity extends AppWidgetProvider{
public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
for(int i=0; i<appWidgetIds.length; i++){
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, MyLockScreenActivity.class);
PendingIntent pending = PendingIntent.getActivity(context, 0,intent, 0);
Log.e("in main","onclick");
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.activity_main);
views.setOnClickPendingIntent(R.id.button, pending);
appWidgetManager.updateAppWidget(appWidgetId,views);
Toast.makeText(context, "widget added", Toast.LENGTH_SHORT).show();
}
}
}
这是我的小部件代码。而不是调用另一个活动,我想从普通的java类调用方法。