using global variable in android extends application
2011-05-11 14:57
381 查看
1.extends application,this class must in android pakage; and in AndroidManifest.xml set android:name="GucApplication ";
2.set value and get value
?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.guc.android" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <application android:name="GucApplication" android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> <activity android:name="WelcomeActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
package com.guc.android; import java.util.HashMap; import java.util.Map; import android.app.Application; import android.content.Context; public class GucApplication extends Application { private static GucApplication instance; private Map<String, String> appContext; public GucApplication() { appContext=new HashMap<String, String>(); instance = this; } public static Context getContext() { return instance; } public Map<String, String> getAppContext() { return appContext; } public void setAppContext(String key, String value) { appContext.put(key, value); } }
2.set value and get value
Map<String, String> o = (Map<String, String>) this.getListAdapter().getItem(position); String archive=o.get("fmember_id"); GucApplication gucAppContext=(GucApplication)getApplicationContext(); gucAppContext.setAppContext("archive",archive);
GucApplication gucAppContext=(GucApplication)getApplicationContext(); String archive=gucAppContext.getAppContext().get("archive");
相关文章推荐
- 在Android程序里显示等待滚动圈(使用ProgressDialog)| Show waiting rolling circle in android application (using ProgressDialog)
- Using C++ Code in Android Application
- Creating custom headers and footers in Application level events using global.asax
- Creating custom headers and footers in Application level events using global.asax
- How to declare global variables in Android? --- Application Subclasses
- Using SQLite in Android Application
- Using SQLite in Android Application
- Undefined variable: pdo in <b>/var/www/html/gm/application/library/db/dbBase.php
- using Camel in a Web Application
- how to force global variable which define in a static library to initialize?
- Android开发问题之--Validates using resource IDs in a switch statement in Android library module
- using mysql in java application
- Asynchronous HTTP Requests in Android Using Volley
- Using iCloud Storage in an iOS 5 iPhone Application
- Automating Excel 2007 and creating charts using C++ MFC application in Visual Studio 2008
- Using custom attr in Android
- Using Android monkeyrunner from Eclipse in Windows
- MVC architecture in ASP.Net using C# and Microsoft Data Access Application block
- Using @Variable Functions in the Universe