zoukankan      html  css  js  c++  java
  • android 应用架构随笔二(定义BaseApplication并配置Application)

    定义BaseApplication并配置Application

    import android.app.Application;
    import android.os.Handler;
    /**
     * 
     * ============================================================
     **/
    public class BaseApplication extends Application {
        //获取到主线程的上下文
        private static BaseApplication mContext;
        //获取到主线程的handler
        private static Handler mMainThreadHanler;
        //获取到主线程
        private static Thread mMainThread;
        //获取到主线程的id
        private static int mMainThreadId;
        
        
        
        @Override
        public void onCreate() {
            // TODO Auto-generated method stub
            super.onCreate();
            this.mContext = this;
            this.mMainThreadHanler = new Handler();
            this.mMainThread = Thread.currentThread();
            //获取到调用线程的id
            this.mMainThreadId = android.os.Process.myTid();
        }
        
        public static BaseApplication getApplication(){
            return mContext;
        }
        
        public static Handler getMainThreadHandler(){
            return mMainThreadHanler;
        }
        
        public static Thread getMainThread(){
            return mMainThread;
        }
        
        public static int getMainThreadId(){
            return mMainThreadId;
        }
        
        
        
        
        
        
    }
    BaseApplication
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.heima.googleplay"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="10"
            android:targetSdkVersion="17" />
    
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    
        <application
            android:name="包名.application.BaseApplication"
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.heima.googleplay.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>
    manifest

    <application
    android:name="包名.application.BaseApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
    android:name="com.heima.googleplay.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    </application>

  • 相关阅读:
    观光公交
    审查(银)
    小木棍 && 愤怒的小鸟
    SDOI2008 仪仗队 && SDOI2012 Longge的问题 && q
    斗地主 && Mayan游戏 && 作业调度方案
    过河
    跳跳棋
    count
    Cow Tennis Tournament
    luogu P1534不高兴的津津(升级版)
  • 原文地址:https://www.cnblogs.com/ecollab/p/6070016.html
Copyright © 2011-2022 走看看