我有小部件应用程序,我想在Textview值
中获取MainActivity.class此MainActivity.class:
public class MainActivity extends Activity{
protected void onCreate(Bundle savedInstanceState) {
Intent widgetIntent = new Intent(this,widget1.class);
//send value
widgetIntent.putExtra("value",(TextView)findViewById(R.id.tvValue).getText());
sendBroadcast(widgetIntent);
}
}
这个widget1.class:
public class widget1 extends AppWidgetProvider {
private String value;
private Bundle getVerseData;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
getVerseData = intent.getExtras();
value= getVerseData.getString("value");
super.onReceive(context, intent);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; i++) {
int currentWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pending = PendingIntent.getActivity(context, 0,
intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.ygs_widget);
views.setTextViewText(R.id.tvYgsGun,value);
views.setOnClickPendingIntent(R.id.ygsRelative, pending);
appWidgetManager.updateAppWidget(currentWidgetId, views);
}
}
}
但是价值是空的。为什么?我在等你的答案。谢谢你