这将是您的清单,此类可用于设置值,然后在任何项目 java 类中获取值
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="package name"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/somee" android:label="@string/app_name" android:noHistory="true" android:name="MainApplication" >
<activity android:name=".first Page" android:noHistory="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
然后在您的主应用程序中
public class MainApplication extends Application{
private static MainApplication instance;
private String _sUserId;
@Override
public void onCreate(){
super.onCreate();
instance=this;
}
public static Main Application getInstance(){
return instance;
}
public void setUserId(String s){
_sUserId=s;
}
public String getUserId(){
return _sUserId;
}
您可以在任何 java 文件中获取值和设置值,例如
MainApplication o=((MainApplication)getApplicationContext());
Integer UserID=o.getUserID();//you need to set user where you want to to get the value of user id