大佬教程收集整理的这篇文章主要介绍了强制Android小部件更新,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public class TestWidget extends appwidgetprovider { public void onupdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds) { final int n = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this provider for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; // Create an Intent to launch updateservice Intent intent = new Intent(context,updateservice.class); PendingIntent pendingIntent = PendingIntent.getservice(context,intent,0); // Get the layout for the App Widget and attach an on-click listener to the button RemoteViews views = new RemoteViews(context.getPackagename(),R.layout.appwidget_provider_layout); views.setOnClickPendingIntent(R.id.button,pendingIntent); // Tell the AppWidgetManager to perform an update on the current App Widget appWidgetManager.updateAppWidget(appWidgetId,views); } } public static class updateservice extends service { @Override public int onStartCommand(Intent intent,int flags,int startId) { //process your click here return START_NOT_STICKY; } } }
<service android:name="com.xxx.yyy.TestWidget$updateservice">
您可以在SDK中的维基词典示例中找到updateservice实现的另一个示例
而这里还有另一个好办法Clickable widgets in android
以上是大佬教程为你收集整理的强制Android小部件更新全部内容,希望文章能够帮你解决强制Android小部件更新所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。