2011-07-07 127 views

回答

1

我不知道这一点,我havne't做了一个小部件,但我认为当你创建窗口小部件,小部件onCreate()方法被调用。尝试将你的startActivity(Intent)放在那里,看看是否有效。

1

控件没有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