20 . Observable.interval()不起作用的解決辦法 2016-11-25
When you use the default scheduler (Schedulers.computation()) the
observable emits on another thread. If your program exits just after
the subscribe then the observable is not given a chance to run. Put in
a long sleep just after the subscribe() call and you will see it working.
當您使用默認調度程序(Schedulers.computation())observable發(fā)
出在另一個線程。 如果你的程序在subscribe之后退出,那么
observable不會有機會運行。 在subscribe()調用之后進入長睡眠,
你會看到它工作。
19.android studio 引入aar包
1.將aar包拷貝到model的libs文件下
2.在model的build.gradle文件中加入
/*和android配置同級*/
repositories{
flatDir {
dirs 'libs'
}}
dependencies {
compile(name: 'aar文件名', ext: 'aar')
}
備注:如果aar引用了第三方的開發(fā)包,則第三方開發(fā)包是不會打包在aar文件中的,需要單獨引入
18.java中靜態(tài)塊的相關知識:
1.static{}這個程序運行的時候只會執(zhí)行一次,而且是優(yōu)先執(zhí)行。
2、對于{}程序每次運行的時候都會執(zhí)行一次,落后于static{},但優(yōu)先于構造方法。
3、A()構造方法最后執(zhí)行,每次創(chuàng)建對象(new)的時候就會執(zhí)行一次。
以上更新于 2016-8-11
17.webView中存在編輯框時,軟鍵盤彈出時,布局不會自動頂上去?
當我們在布局中有webView的Activity中,設置了支持軟鍵盤彈出后布局
可以被頂上去,發(fā)現無效時,此時可能是我們設置的Activity的主題
(theme)出現問題了,主題中的android:windowTranslucentStatus要設置成false.
以上更新于 2016-8-5
16.使用Intent傳遞數據量大時(尤其是bitmap對象
),app沒反應?
android四大組件之間Intent傳遞數據,數據不能過大,基本要小于1M,不然會導致程序黑屏,ANR.
15.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
代碼中去掉標題欄使用時報錯?
當我們的Activity是繼承自Activity或者是FragmentActivity時不會有問題;但當我們繼承的是AppCompatActivity時就會報錯,
解決方法是 getSupportActionBar().hide()或者是這是主題為Theme.AppCompat.Light.NoActionBar;
14.在androidAPI16中NoScrollGridView的item布局的根布局背景色設置為白色時候,在代碼中調用setTopBarBgColor()設置topBar的背景色時,item的背景會和topBar背景一樣而在API16以上不會出現。
可以在xml直接設置,不用代碼設置來避免
13.在使用第三方庫經常報有一些v4,v7包沖突問題?
在封裝library的時候,盡量不要引入第三方包,v4,v7等自帶的包也是一樣盡量不要引入,避免以后工程依賴的時候,包或者包內文件產生沖突。
對于沖突的包,改成一樣的就可以解決了。
12.手機屏幕的高度包括哪些?
android手機的屏幕的高度不包括[狀態(tài)欄],包括[標題欄(actionBar)]和[顯示區(qū)];方法getWindowVisibleDisplayFrame(rect)獲取的是顯示區(qū)的范圍
11.static修飾的class、代碼塊、變量什么時候執(zhí)行?
static 修飾的代碼塊,變量和方法在編譯的時候就已經執(zhí)行了,(在程序開始執(zhí)行前)
10.ContentProvider的onCreate()什么時候執(zhí)行?
contentProvider的oncreate()方法在程序Application的oncreate()方法前執(zhí)行。
9.Can't load native library.CPU arch invalid for this build?
CPU_ABI : armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips, mips64.
復制你的.so文件到<project>/libs/(armeabi|armeabi-v7a|x86|...)
Android Studio復制到jniLibs文件夾下,eclipse 復制到libs文件夾下。
注意當你使用多個第三方庫的時候時,而且這些庫有使用.so文件,創(chuàng)建文件夾時應保證【最少原則】。比如:一個庫中.so文件支持armeabi,armeabi-v7a,x86,另外一個庫卻只支持armeabi-v7a這樣也會造成該問題的產生,因為支持x86的機器會在另一個庫中找不到.so文件而保錯。
8.Parcelable接口使用時,數據傳遞錯誤原因
//實體類的屬性的寫入和讀取順序不一致,造成的。例如:
public class ImageItem implements Parcelable {
public String imageId;
public String imagePath;//原圖的路徑
public boolean isSelected;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
//寫入的順序
dest.writeString(imageId);
dest.writeString(imagePath);
dest.writeByte((byte) (isSelected ? 1 : 0));
}
public static final Parcelable.Creator<ImageItem> CREATOR = new Parcelable.Creator<ImageItem>() {
@Override
public ImageItem createFromParcel(Parcel source) {
//讀取要和寫入的順序一致,否則會造成數據讀取錯亂
ImageItem item = new ImageItem();
item.imageId = source.readString();
item.imagePath = source.readString();
item.isSelected = (source.readByte() != 0);
return item;
}
@Override
public ImageItem[] newArray(int size) {
return new ImageItem[size];
}
};
}
7,如何不讓任務棧顯示在最近任務棧列表里面?
- 將任務棧的rootActivity的excludeFromRecents設置為true
- 官網對excludeFromRecents的解釋如下:
android:excludeFromRecents
Whether or not the task initiated by this activity should be
excluded from the list of recently used applications, the
overview screen. That is, when this activity is the root activity
of a new task, this attribute determines whether the task
should not appear in the list of recent apps. Set "true" if the
task should be excluded from the list; set "false" if it should be
included. The default value is "false".
6.Android應用第一次安裝成功點擊“打開”后Home鍵切出應用后再點擊桌面圖標返回導致應用重啟問題
/*在應用程序設置<action android:name="android.intent.action.MAIN" />應用程序入口
Activity的onCreate方法中加入上面的判斷,完美解決應用程序多次重
啟問題。
*/
if((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0){
finish();
return;
}
5.Fragment中點擊事件使用隱式綁定會報錯?
//fragment中不能使用隱式綁定點擊事件。
1.建議使用顯示綁定
2.參考網址:
http://stackoverflow.com/questions/21192386/android-
fragment-onclick-button-method
4.Fragment中的setUserVisibleHint不執(zhí)行?
1.viewpager+fragment模式setUserVisibleHint()方法是執(zhí)行的,其
中第一個fragment的該方法執(zhí)行兩次,第一次在onAttch()方法執(zhí)行之
前,第二次在onCreate()方法執(zhí)行之后,在onCreateView()方法執(zhí)行
之前。當我們把fragment緩存起來時,該方法還是會執(zhí)行的。
2.當我們自己切換fragment時,transition.add(R.id.main_content,
mainFragment);(獲取用replace),fragment 中的
setUserVisibleHint()是不執(zhí)行的。
3.android開發(fā)中的圖標大小?
drawable-mdpi,hdpi,xhdpi,xxhdpi,對應的icon大小分別是24px,32px,48px,72px
2.ScrollView嵌套RecyclerView,recyclerView不顯示問題?
建議使用是其他方式,本人使用NoScrollGridView ,NoScrollListView來替換RecyclerView。
1.布局中CoordinatorLayout中包含自定義ViewGroup并且ViewGroup的寬高設置為Match_parent情況下,onLayout調用時在Api21以上,返回過來的高度是全屏的高度(包括狀態(tài)欄),而在api21以下正常(高度不包含狀態(tài)欄)?
//問題布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.myapplication.MainActivity">
<com.myapplication.MyLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="這是按鈕" />
</com.myapplication.MyLayout>
</android.support.design.widget.CoordinatorLayout>
//正常布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.myapplication.MainActivity">
<include layout="@layout/content_main"/>
</android.support.design.widget.CoordinatorLayout>
//布局content_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.myapplication.MainActivity"
tools:showIn="@layout/activity_main">
<com.myapplication.MyLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="這是按鈕" />
</com.myapplication.MyLayout>
</RelativeLayout>