102_widget的点击事件

来源:互联网 发布:权力的游戏大麻雀知乎 编辑:程序博客网 时间:2024/05/20 02:27

//点击后,发一个自定义的延迟意图。在应用程序中,通过广播接收者,接收该延迟意图,然后。。。。。。。。

一、在更新widge界面的服务中


task = new TimerTask() {
@Override
public void run() {
AppWidgetManager awm = AppWidgetManager.getInstance(getApplicationContext());
ComponentName component = new ComponentName(getApplicationContext(), MyWidget.class);
RemoteViews views = new RemoteViews(getPackageName(),R.layout.process_widget);
views.setTextViewText(R.id.process_count,"正在运行:");
views.setTextViewText(R.id.process_memory,"可用内存:");



Intent intent = new Intent();
intent.setAction("
com.itheima.killall");  //自定义的意图
//设置一个自定义的广播事件   动作  com.itheima.killall
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
views.setOnClickPendingIntent(R.id.btn_clear, pendingIntent);


awm.updateAppWidget(component, views);


}
};


二、自定义一个广播接收者,过滤自定义的意图("com.itheima.killall")




0 0
原创粉丝点击