}
public class TestActivity extends Activity {
String name="";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button=(Button)findViewById(R.id.button);
EditText et=(EditText)findViewById(R.id.et);
Bundle bundle=this.getIntent().getExtras();
try{
if(bundle.getString("name")!=null){
name=bundle.getString("name");
et.setText(name);
}
}catch(Exception e){
e.printStackTrace();
}
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(TestActivity.this, name, Toast.LENGTH_SHORT).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gys.widget"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".WidgetDemo"
android:icon="@drawable/huaixiao"
android:label="@string/widget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget"
/>
</receiver>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="124dip"
android:minHeight="50dip"
android:updatePeriodMillis="180001"
android:initialLayout="@layout/widgetlayout"
/>