安卓筆記20170112

2021-07-25 23:47:26 字數 1282 閱讀 3417

一,全域性獲取context的技巧

public static context getcontext()}

...

...>

二,使用intent傳遞物件

1.serializable方式

public class person implements serializable 

public void setname(string name)

public int getage()

public void setage(int age)

}

在傳送方活動裡的**如下

person person = new person();

person.setname("tom");

person.setage(20);

intent intent = new intent(firstactivity.this, secondactivity.class);

intent.putextra("person_data", person);

startactivity(intent);

在接收方活動裡**如下

person person = (person) getintent().getserializableextra("person_data");

2.parcelable方式

serializable是將物件進行序列化, parcelable方式的實現原理是將乙個完整的物件進行分解,分解後的每一部分都是intent所支援的資料型別

public class person implements parcelable 

@override

public void writetoparcel(parcel dest, int flags)

public static final parcelable.creatorcreator = new parcelable.creator()

@override

public person newarray(int size)

};}

傳送方活動裡的傳遞**是一樣的,接收方活動**如下

person person = (person) getintent().getparcelableextra("person_data");



安卓 筆記 一

設定主活動 在androidmanifest檔案中 完成註冊 p36 若沒有設定主程式 此類程式仍可正常安裝,但無法在啟動器中開啟程式,僅做第三方服務或是內部進行呼叫。活動中 可以通過findviewbyid 方法來獲得 布局檔案中的元素,例如 button button button findvi...

安卓筆記 ContentProvider

四大元件之一。contentprovider是不同應用程式之間進行資料交換的標準api。當乙個應用程式暴露自己的資料給其他程式使用時,該應用程式通過提供contentprovider來實現 其他應用程式通過contentresolver來操作contentprovider暴露的資料。contentp...

安卓許可權筆記

筆記,本人學識有限,有錯誤請指正。在寫發現許可權挺重要的,幾乎都得用到,因為本人手機為安卓9.0版本,做啥都要申請許可權,寫了好幾個,都需要用到,因此,趁這個時間,看一下許可權方面,整理一段能夠直接用的許可權申請 高版本的安卓什麼許可權都需要獲取許可權 動態獲取。原本 低版本 是直接在android...