Reputation: 3874
I would like to launch an Activity, when the user adds the widget on the launcher. How can I do that ?
The onReceive method is called too often. And with onEnabled, it simply doesn't launch.
How can I do that ?
Tkx
Upvotes: 0
Views: 214
Reputation: 4910
Widget Doesn't have a OnCreate() method. Instead it has a onEnabled() Method.
@Override
public void onEnabled (Context context){
super.onEnabled(context);
Toast.makeText(context, "Launching Config Activity", Toast.LENGTH_SHORT).show();
//Launching the Widget Config Activity on creating widget first time
myIntent = new Intent(context, ConfigActivity.class);
//Needed because activity is launched from outside another activity
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myIntent.putExtra("WIDGET_SIZE", "default");
context.startActivity(myIntent);
}
Remember you need to add the widget to the home screen using code after the configuration is complete with necessary changes.
Refer more here: http://developer.android.com/guide/topics/appwidgets/index.html
Upvotes: 1
Reputation: 11439
I'm not sure on this, I havne't done a widget yet, but I think when you create a widget, the widgets onCreate() method gets called. Try placing your startActivity(Intent) in there and see if that works.
Upvotes: 1