java static段_java static段代码调用时间

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

public classSmsManager {private staticSmsManager[] sInstance;private int mPhoneId = -1;static{

sInstance= new SmsManager[2];for(int i =0; i<2; i++){

sInstance[0] = newSmsManager(i);

Log.d("jimwind","SmsManager static "+i);

}

}private SmsManager(intphoneId){

mPhoneId=phoneId;

}public static SmsManager getDefault(intphoneId){if(phoneId > 1)throw new IllegalArgumentException("phoneId exceeds phoneCount");

Log.d("jimwind","SmsManager getDefault");returnsInstance[phoneId];

}

}

java object static

使用类时,调用SmsManager.getDefault(0);先加载类,运行static代码段,然后运行getDefault();

TelephonyManager也是类似的方式。

---------------------------------------------------------------------------------------------

ITelephony.Stub.asInterface

ITelephony.aidl在编译时不使用,而是使用用Android的SDK中提供了一个aidl工具生成的ITelephony.java

ITelephony.java 就相当于两个进程间的通信协议。

实验:

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

/** Copyright (C) 2007 The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

*http://www.apache.org/licenses/LICENSE-2.0*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.*/

packagecom.mi.telephony;/*** Interface used to interact with the phone. Mostly this is used by the

* TelephonyManager class. A few places are still using this directly.

* Please clean them up if possible and use TelephonyManager insteadl.

*

* {@hide}*/

interfaceITelephony {/*** Dial a number. This doesn't place the call. It displays

* the Dialer screen.

*@paramnumber the number to be dialed. If null, this

* would display the Dialer screen with no number pre-filled.*/

voiddial(String number);

}

ITelephony.aidl

放在com/mi/telephony下面

>aidl com\mi\telephony\ITelephony.aidl

生成ITelephony.java

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

/** This file is auto-generated. DO NOT MODIFY.

* Original file: com\\mi\\telephony\\ITelephony.aidl*/

packagecom.mi.telephony;/*** Interface used to interact with the phone. Mostly this is used by the

* TelephonyManager class. A few places are still using this directly.

* Please clean them up if possible and use TelephonyManager insteadl.

*

* {@hide}*/

public interface ITelephony extendsandroid.os.IInterface

{/**Local-side IPC implementation stub class.*/

public static abstract class Stub extends android.os.Binder implementscom.mi.telephony.ITelephony

{private static final java.lang.String DESCRIPTOR = "com.mi.telephony.ITelephony";/**Construct the stub at attach it to the interface.*/

publicStub()

{this.attachInterface(this, DESCRIPTOR);

}/*** Cast an IBinder object into an com.mi.telephony.ITelephony interface,

* generating a proxy if needed.*/

public staticcom.mi.telephony.ITelephony asInterface(android.os.IBinder obj)

{if ((obj==null)) {return null;

}

android.os.IInterface iin=(android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);if (((iin!=null)&&(iin instanceofcom.mi.telephony.ITelephony))) {return((com.mi.telephony.ITelephony)iin);

}return newcom.mi.telephony.ITelephony.Stub.Proxy(obj);

}publicandroid.os.IBinder asBinder()

{return this;

}

@Overridepublic boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throwsandroid.os.RemoteException

{switch(code)

{caseINTERFACE_TRANSACTION:

{

reply.writeString(DESCRIPTOR);return true;

}caseTRANSACTION_dial:

{

data.enforceInterface(DESCRIPTOR);

java.lang.String _arg0;

_arg0=data.readString();this.dial(_arg0);

reply.writeNoException();return true;

}

}return super.onTransact(code, data, reply, flags);

}private static class Proxy implementscom.mi.telephony.ITelephony

{privateandroid.os.IBinder mRemote;

Proxy(android.os.IBinder remote)

{

mRemote=remote;

}publicandroid.os.IBinder asBinder()

{returnmRemote;

}publicjava.lang.String getInterfaceDescriptor()

{returnDESCRIPTOR;

}/*** Dial a number. This doesn't place the call. It displays

* the Dialer screen.

*@paramnumber the number to be dialed. If null, this

* would display the Dialer screen with no number pre-filled.*/

public void dial(java.lang.String number) throwsandroid.os.RemoteException

{

android.os.Parcel _data=android.os.Parcel.obtain();

android.os.Parcel _reply=android.os.Parcel.obtain();try{

_data.writeInterfaceToken(DESCRIPTOR);

_data.writeString(number);

mRemote.transact(Stub.TRANSACTION_dial, _data, _reply,0);

_reply.readException();

}finally{

_reply.recycle();

_data.recycle();

}

}

}static final int TRANSACTION_dial = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);

}/*** Dial a number. This doesn't place the call. It displays

* the Dialer screen.

*@paramnumber the number to be dialed. If null, this

* would display the Dialer screen with no number pre-filled.*/

public void dial(java.lang.String number) throwsandroid.os.RemoteException;

}

ITelephony.java

---------------------------------------------------------------------------------------------

android 关于接口的使用:

以Mms中ConversationList与DraftCache.OnDraftChangedListener接口调用关系分析

1、 ConversationList implements DraftCache.OnDraftChangedListener

实现接口中的函数onDraftChanged

2、先查看在ConversationList类中,对类DraftCache的使用

列出:

DraftCache.getInstance().addOnDraftChangedListener(this);

DraftCache.getInstance().refresh();

DraftCache.getInstance().setDraftState();

DraftCache.getInstance().getSavingDraft());

DraftCache.getInstance().removeOnDraftChangedListener(this);

3、再查看在DraftCache类中,对接口OnDraftChangedListener方法onDraftChanged中的调用。

列出:

refresh() -> private synchronized void rebuildCache()->onDraftChanged

public synchronized void setDraftState() -> onDraftChanged

这里,onDraftChanged是接口使用者自己实现,调用关系由定义接口的类确定。(如果接口使用者直接调用就没有意义了)

-----------------------------------------------------------------------------------------

类AsyncQueryHandler 的使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值