來源:如何的onReceive方法更新的TextView在控件提供者
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
String s = "MusicPlayer";
if (MusicPlayerActivity.currentActivity != null) {
s = MusicPlayerActivity.currentActivity.getCurrentTrackName();
} else {
Log.d(MusicPlayerActivity.TAG,"STARTING ACTIVITY FROM WIDGET");
Intent intent1 = new Intent(context, MusicPlayerActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
// I WANT TO UPDATE TEXT VIEW HERE
if (MusicPlayerActivity.currentActivity != null)
if (intent.getAction().equals(ACTION_WIDGET_NEXT)) {
MusicPlayerActivity.currentActivity.playNext();
} else if (intent.getAction().equals(ACTION_WIDGET_PLAY)) {
MusicPlayerActivity.currentActivity.playPause();
} else if (intent.getAction().equals(ACTION_WIDGET_PREV)) {
MusicPlayerActivity.currentActivity.playPrevious();
}
}
我試過的東西與此代碼:
Log.d(MusicPlayerActivity.TAG,s);
remoteViews.setTextViewText(R.id.w_trackInfo, s);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.w_trackInfo);
但如果我把它放在評論位置,這並不工作。任何幫助讚賞。
只是讓remoteViews公共靜態,然後嘗試設置任何地方 –
不,是沒有任何工作,似乎它需要被提交到小工具不知何故。 – Dejan