??????WkjTest?????У????MainActivityTest????????????Run As....????Android JUnit Test?????????????????????豸?????г??????Junit???????????????test001??????????????ò????????????????????????????????????
???????????????????????????????testTemp001????????????????????????????????????????????????????????????????????????????????????????????????е??????????????
???????濪???д????????????????????????????
??????????????????????MVC????????????????????????????MVC??????????Activity???????View??View???Model???????????????????testTemp001?????????????????????
??????Android??????????????Model??????Model????к??????????????????????Application????????Model????????AppModel?????Application??????????????Model???ò???Singleton???????????????????????????????Activity?л???????????????????????У????Model?д???welcom_msg??????????MainActivity?в?????????Model??????????????????С?
????AppModel???????????
package com.bjcic.wkj;
import android.app.Application;
public class AppModel extends Application {
// ??????????????
public void onCreate() {
super.onCreate();
welcomeMsg = getString(R.string.welcome_msg);
}
public void onTerminate() {
super.onTerminate();
}
// ???????????????
private String welcomeMsg = null;
public String getWelcomeMsg() {
return welcomeMsg;
}
public void setWelcomeMsg(String welcomeMsg) {
this.welcomeMsg = welcomeMsg;
}
}
??MainActivity????????′???
[java] view plaincopy
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
appModel = (AppModel)getApplication();
}
@Override
public void onResume() {
super.onResume();
((TextView)findViewById(R.id.j_titleTxtv)).setText(appModel.getWelcomeMsg());
}
private AppModel appModel = null;
????????Manifest?????????
<application
android:allowBackup="true"
android:name=".AppModel"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
???????????WkjTest????????MainActivityTest????????Run As .... =>Android JUnit Test?????Junit??????????????????????????????????????????????????????????