android

来源:互联网 发布:数控折弯机编程视频 编辑:程序博客网 时间:2024/05/15 19:42

通过Application传递参数:

1、自定义一个MyApplication如:

package com.jxj.androidlife;

import android.app.Application;

public class MyApplication extends Application {

    private String empNo;
    
    @Override
    public void onCreate() {
        super.onCreate();
        this.setEmpNo("001");
    }

    public String getEmpNo) {
        return empNo;
    }

    public void setEmpNo(String empNo) {
        this.empNo = empNo;
    }
}

2、在AndroidManifest中设置id:

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

。。。。。


改成如下:

    <application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >



3、

通过下面代码即可获取到Application

MyApplication myApp=(MyApplication)this.getApplication();




0 0
原创粉丝点击