定义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. Selenium2学习-013-WebUI自动化实战实例-011-WebElement.getText()值为空问题探索及解决

    今天有个朋友在群里问 WebElement.getText() 值为空,当你发现取到的值为空的时候,会不会郁闷呢?明明看到的值不为空,脚本看着也没有问题啊,为何取到的值为空呢!!!万千纠结啊,若是长时 ...

  2. DelayQueue

    1.结构 使用的是PriorityQueue来作为底层的存储 元素需要实现Delayed接口,该接口继承了comparable接口 DelayQueue的队头元素是根据comparable排在队首的元 ...

  3. ViewFlipper、ViewPager和Gallery

    1.ViewFlipper 1)View切换的控件—ViewFlipper介绍 ViewFilpper类继承于ViewAnimator类.而ViewAnimator类继承于FrameLayout. 查 ...

  4. UIPickerView详解

    一.UIPickerView 1.UIPickerView的常见属性 // 数据源(用来告诉UIPickerView有多少列多少行) @property(nonatomic,assign) id< ...

  5. swift 同步加载图片

    import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...

  6. js随机更换

    如果想实现“随机”切换图像,那么我们要使用到几个Math()对象 第一个是random()函数,函数的功能是产生随机数,如果书写为 var a=Math.random() 那么所产生的随机数是0-1( ...

  7. Nand Flash与Nor Flash的区别

    区别:http://zhidao.baidu.com/question/1068445.html?qbl=relate_question_0&word=Serial%20Flash%20%D3 ...

  8. Request、Servlet及其子接口

    最近看tomcat源码,这类接口多的有点眩,整理出来看一下.(基于tomcat4) javax.servlet.ServletRequset接口,和org.apache.catalina.Reques ...

  9. java collections读书笔记(8)collection框架总览(1)

  10. Lintcode: Flip Bits

    Determine the number of bits required to flip if you want to convert integer n to integer m. Have yo ...