Android開發(fā)過程中遇到的問題

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>



最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,501評論 6 544
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發(fā)現死者居然都...
    沈念sama閱讀 99,673評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,610評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,939評論 1 318
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,668評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 56,004評論 1 329
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 44,001評論 3 449
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,173評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發(fā)現了一具尸體,經...
    沈念sama閱讀 49,705評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,426評論 3 359
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,656評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,139評論 5 364
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 44,833評論 3 350
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,247評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,580評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,371評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,621評論 2 380

推薦閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,761評論 25 708
  • afinalAfinal是一個android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,486評論 2 45
  • 早晨四點醒來,外面是這樣的,山頭微現。 上午6個小時的行程總的來說是沉默的,卻是充滿力量的。大家都冒著大雨沉默著在...
    聽風看樹望天空閱讀 189評論 0 2
  • 最近接二連三的吵架 讓我一直不開心 感情到現在真的挺不容易的 我不想因為一點小事吵架 可是你說聊天 不就不你是要兩...
    五六七的五閱讀 136評論 0 0
  • 1. 小數點后進一 :=ROUNDUP(A1,0)
    蘇小姐請moveon閱讀 174評論 0 0