我做了一个小部件,一旦放在主屏幕上就会启动一个活动
所以我有:
public class WidgetActivity extends AppWidgetProvider
{
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgets) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_activity);
Intent intent = new Intent(context, Info.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
remoteViews.setOnClickPendingIntent(R.id.Widget, pendingIntent);
}
}
和
public class Info extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.widget_activity_info);
}
}
但是在成功启动 widget_activity_info.xml 后,按返回或主页后,小部件不在主屏幕上。我在这里错过了什么吗?在我让它启动新活动之前,小部件会留在屏幕上。