当用户在启动器上添加小工具时,我想启动一个活动。我该怎么做呢?
onReceive方法调用太频繁。而对于onEnabled,它根本就不能启动。
我该怎么做呢?
Tkx
发布于 2011-07-07 22:55:57
我不确定这一点,我还没有做过小部件,但我认为当你创建一个小部件时,小部件的onCreate()方法会被调用。试着把你的startActivity(Intent)放进去,看看能不能用。
发布于 2013-06-12 17:44:28
小部件没有OnCreate()方法。相反,它有一个onEnabled()方法。
@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);
}请记住,在配置完成并进行必要的更改后,您需要使用代码将小部件添加到主屏幕。
Refer more here: http://developer.android.com/guide/topics/appwidgets/index.html
https://stackoverflow.com/questions/6611172
复制相似问题