zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

android getLong()用法

Android 用法
2023-09-14 09:09:54 时间

1、frameworks/base/core/java/com/android/internal/widget/LockPatternUtils.java

    public staticboolean getLong(String key,long def) {}

    <1>例1

    boolean ret = getLong("test", 1);

    第二个参数(boolean def):If the key does not exist, or has any other value, then the default result is returned.(如果字段不存在返回预先定义的值,如果存在返回其值)

    @param2 def a default value to return

    注:如果没有定义”test"字段,返回1。1即为定义的default value.

    <2>例2

    setLong("test", 0); 

    boolean ret = getLong("test", 1);

    此时ret返回为0,因为setLong()设置为0;

 setLong("test",0)等价于:

try {                    ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings")).setLong("test", 0, getCurrentOrCallingUserId());

   } catch (RemoteException re) {

       Log.e(TAG, "Couldn't write long " + re);

   }catch (NullPointerException re) {

       Log.d(TAG, "lock_settings service is disabled " + re);

   }