2011-07-07 124 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