2013年10月8日星期二

android shared global problem of data


afternoon encounter the problem of passing parameters between screens , after pointing know they can rewrite Application to save global data

then the instance http://www.eoeandroid.com/thread-30257-1-1.html Posts

made ​​a small example , but always reported ClassCastException, an error in the code below android.app.Application seek expert advice

appTest.java
public class appTest extends Activity {
/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
((App) getApplication ()). setDemo ("sss");
String demo = ((App) getApplication ()). getDemo ();
}
}

rewritten Application Files
App.java

import android.app.Application;

public class App extends Application {

private String demo;

public String getDemo () {
return demo;
}

public void setDemo (String demo) {
this.demo = demo;
}
}

AndroidManifest.xml


package = "com.appTest"
android: versionCode = "1"
android: versionName = "1.0">

android: label = "@ string / app_name">







android: icon = "@ drawable / icon"
android: label = "@ string / app_name">


App.java and appTest.java all in one package com.appTest

seek expert advice ! ~ ! ~ ! ~ Thank you, brother first


------ Solution ------------------------------------ --------
get to pick points up :)
------ Solution ------------------- -------------------------
do not understand how
------ eference -------- -------------------------------
solve the problem is AndroidManifest configured not to android: name = ". App" into the first configuration where one application like
------ eference ----------------------- ----------------
http://www.eoeandroid.com/thread-30257-1-1.html
------ eference - -------------------------------------
this could take minutes ;

没有评论:

发表评论