简体   繁体   中英

Getting ANDROID_ID Trying to understand the java

I'm still new to programming/Java/Android so I'm trying to understand everything I do and trying to figure out how to properly read the reference section of developer.android.com and so maybe one of you guys can help me out. Thanks in advance

These calls get me the ANDROID_ID. They both give me the same output. I just do not understand how the Second Way works. It shouldn't work in my opinion.

First way

AndroidID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

Second way

AndroidID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

Why does it work like that?

I used this to find the getString() method. I get the ANDROID_ID. It works perfectly using both calls, but I want to know why it works the second way.

I'm pretty sure the reason is because you have:

import android.provider.Settings.Secure;

In your imports. Similarly you'll find that both DialogInterface and View have different implementations of classes called OnClickListener, but you can still do something like:

// View.OnClickLitener
OnClickListener foo = new OnClickListener(...) {
     ...
}

DialogInterface.OnClickListener bar = new DialogInterface.OnClickListener(...) {
     ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM