定义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>

android 应用架构随笔二(定义BaseApplication并配置Application)的更多相关文章

  1. android 应用架构随笔一(架构搭建)

    1.拷贝积累utils以及PagerTab类 2.定义BaseApplication类 3.定义BaseActivity类 4.改写MainActivity 5.定义布局文件 6.定义BaseFrag ...

  2. android 项目学习随笔二十一(IM、语音识别、机器人、统计、扫描二维码、条形码)

    语音识别:科大讯飞语音云 http://www.xfyun.cn/ 语音机器人模拟 public class TalkBean { public String text; public boolean ...

  3. android 项目学习随笔二十(屏幕适配)

    1.图片适配 放入相同名称的资源文件,机器根据不同分辨率找相近的资源 240*320 ldpi 320*480 mdpi 480*800 hdpi 720*1280 xhdpi 2.布局适配 在不同的 ...

  4. android 项目学习随笔二(引导页 )

    1.引导页 1.定义灰色.红色圆点的shape XML文件 2.定义布局文件,利用相对布局文件定位,利用线性布局加载灰色圆点,imageview加载红色圆点 3.android.support.v4. ...

  5. android 应用架构随笔六(Loading加载页面)

    import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import com.heima ...

  6. android 应用架构随笔五(ActionBar与侧滑菜单DrawerLayout)

    ActionBar(V7)的添加非常简单,只需要在AndroidManifest.xml中指定Application或Activity的theme是Theme.Holo或其子类就可以了,在Androi ...

  7. android 应用架构随笔四(View、ViewGroup)

    View表示了用户界面的基本构建模块. 一个View占用了屏幕上的一个矩形区域并且负责界面绘制和事件处理.手机屏幕上所有看得见摸得着的都是View. Activity是四大组件中唯一一个用来和用户进行 ...

  8. android 应用架构随笔三(ListView)

    import java.util.ArrayList; import java.util.List; import com.heima.googleplay.holder.BaseHolder; im ...

  9. Redis缓存项目应用架构设计二

    一.概述 由于架构设计一里面如果多平台公用相同Key的缓存更改配置后需要多平台上传最新的缓存配置文件来更新,比较麻烦,更新了架构设计二实现了缓存配置的集中管理,不过这样有有了过于中心化的问题,后续在看 ...

随机推荐

  1. mac下安装使用svn

    mac自带了svn服务端和客户端,所以只需要简单配置一下就可以使用   转自  http://blog.sina.com.cn/s/blog_677fb16e01011i6l.html 1.创建svn ...

  2. 《Maven实战》阅读笔记

    java -versionmvn -vmvn help:system m2eclipse maven->install MAVEN_OPTS: -Xms128m -Xmx512mmvn clea ...

  3. c# 并行运算

    c# 并行运算 1. Parallel.INVOKE() 看实例: private static Stopwatch watch = new Stopwatch(); private static v ...

  4. MSP430之ADC采集滤波

    占位符 /* 加权平均滤波 */ ] = {,,,,,,,,,,,,}; ++++++++++++; unsigned ; ; i<ADCN; i++) { temp += arr[i]*coe ...

  5. 实现简易的android 直播技术

    Android 的直播,主要使用的是camera采集的数据推流到服务器上,在客户端播放camera采集的数据.采用SurfaceView+ SurfaceTexture来显示camera数据, Sur ...

  6. WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform

    参看:http://www.secdoctor.com/html/yyjs/31101.html

  7. XP下安装MAC OS虚拟系统

    参考baidu经验: http://jingyan.baidu.com/article/e5c39bf5876c8b39d760331a.html 工具: 1.虚拟机软件:vmware worksta ...

  8. Mysql主从库同步错误:1062 Error 'Duplicate entry '1438019'

    mysql主从库同步错误:1062 Error 'Duplicate entry '1438019' for key 'PRIMARY'' on query mysql主从库在同步时会发生1062 L ...

  9. checkbox判断选中

    $("input[type='checkbox']").is(':checked')

  10. vmware lan map

    1,nat: virtrual machine---vmnet8---PC---internet 2,host-only virtual machine(0,1,2...)---vmnet1 3,br ...