Android Fragment 真正的完全解析(下)
上篇部落格中已經介紹了Fragment產生原因,以及一些基本的用法和各種API,如果你還不瞭解,請看:Android Fragment 真正的完全解析(上)。
本篇將介紹上篇部落格提到的:如何管理Fragment回退棧,Fragment如何與Activity互動,Fragment與Activity互動的最佳實踐,沒有檢視的Fragment的用處,使用Fragment建立對話方塊,如何與ActionBar,MenuItem整合等~~
1、管理Fragment回退棧
類似與Android系統為Activity維護一個任務棧,我們也可以通過Activity維護一個回退棧來儲存每次Fragment事務發生的變化。如果你將Fragment任務新增到回退棧,當用戶點選後退按鈕時,將看到上一次的儲存的Fragment。一旦Fragment完全從後退棧中彈出,使用者再次點選後退鍵,則退出當前Activity。
看這樣一個效果圖:
點選第一個按鈕,切換到第二個介面,點選第二個按鈕,切換到第三個介面,然後點選Back鍵依次回退。這像不像初學Android時的Activity跳轉,當然了,這裡肯定不是,不然我就跪了。這裡是Fragment實現的,使用者點選Back,實際是Fragment回退棧不斷的彈棧。
如何新增一個Fragment事務到回退棧:
FragmentTransaction.addToBackStack(String)
下面講解程式碼:很明顯一共是3個Fragment和一個Activity.
先看Activity的佈局檔案:
- <RelativeLayoutxmlns:android
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <FrameLayout
- android:id="@+id/id_content"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- </FrameLayout>
- </RelativeLayout>
MainActivity.java
- package com.zhy.zhy_fragments;
- import android.app.Activity;
- import android.app.FragmentManager;
- import android.app.FragmentTransaction;
- import android.os.Bundle;
- import android.view.Window;
- publicclass MainActivity extends Activity
- {
- @Override
- protectedvoid onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.activity_main);
- FragmentManager fm = getFragmentManager();
- FragmentTransaction tx = fm.beginTransaction();
- tx.add(R.id.id_content, new FragmentOne(),"ONE");
- tx.commit();
- }
- }
下面是FragmentOne
- package com.zhy.zhy_fragments;
- import android.app.Fragment;
- import android.app.FragmentManager;
- import android.app.FragmentTransaction;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.Button;
- publicclass FragmentOne extends Fragment implements OnClickListener
- {
- private Button mBtn;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState)
- {
- View view = inflater.inflate(R.layout.fragment_one, container, false);
- mBtn = (Button) view.findViewById(R.id.id_fragment_one_btn);
- mBtn.setOnClickListener(this);
- return view;
- }
- @Override
- publicvoid onClick(View v)
- {
- FragmentTwo fTwo = new FragmentTwo();
- FragmentManager fm = getFragmentManager();
- FragmentTransaction tx = fm.beginTransaction();
- tx.replace(R.id.id_content, fTwo, "TWO");
- tx.addToBackStack(null);
- tx.commit();
- }
- }
我們在點選FragmentOne中的按鈕時,使用了replace方法,如果你看了前一篇部落格,一定記得replace是remove和add的合體,並且如果不新增事務到回退棧,前一個Fragment例項會被銷燬。這裡很明顯,我們呼叫tx.addToBackStack(null);將當前的事務新增到了回退棧,所以FragmentOne例項不會被銷燬,但是檢視層次依然會被銷燬,即會呼叫onDestoryView和onCreateView,證據就是:仔細看上面的效果圖,我們在跳轉前在文字框輸入的內容,在使用者Back得到第一個介面的時候不見了。
接下來FragmentTwo
- package com.zhy.zhy_fragments;
- import android.app.Fragment;
- import android.app.FragmentManager;
- import android.app.FragmentTransaction;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.Button;
- publicclass FragmentTwo extends Fragment implements OnClickListener
- {
- private Button mBtn ;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState)
- {
- View view = inflater.inflate(R.layout.fragment_two, container, false);
- mBtn = (Button) view.findViewById(R.id.id_fragment_two_btn);
- mBtn.setOnClickListener(this);
- return view ;
- }
- @Override
- publicvoid onClick(View v)
- {
- FragmentThree fThree = new FragmentThree();
- FragmentManager fm = getFragmentManager();
- FragmentTransaction tx = fm.beginTransaction();
- tx.hide(this);
- tx.add(R.id.id_content , fThree, "THREE");
- // tx.replace(R.id.id_content, fThree, "THREE");
- tx.addToBackStack(null);
- tx.commit();
- }
- }
這裡點選時,我們沒有使用replace,而是先隱藏了當前的Fragment,然後添加了FragmentThree的例項,最後將事務新增到回退棧。這樣做的目的是為了給大家提供一種方案:如果不希望檢視重繪該怎麼做,請再次仔細看效果圖,我們在FragmentTwo的EditText填寫的內容,使用者Back回來時,資料還在~~~
最後FragmentThree就是簡單的Toast了:
- package com.zhy.zhy_fragments;
- import android.app.Fragment;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.Toast;
- publicclass FragmentThree extends Fragment implements OnClickListener
- {
- private Button mBtn;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState)
- {
- View view = inflater.inflate(R.layout.fragment_three, container, false);
- mBtn = (Button) view.findViewById(R.id.id_fragment_three_btn);
- mBtn.setOnClickListener(this);
- return view;
- }
- @Override
- publicvoid onClick(View v)
- {
- Toast.makeText(getActivity(), " i am a btn in Fragment three",
- Toast.LENGTH_SHORT).show();
- }
- }
好了,經過上面的介紹,應該已經知道Fragment回退棧是怎麼一回事了,以及hide,replace等各自的應用的場景。
這裡極其注意一點:上面的整體程式碼不具有任何參考價值,純粹為了顯示回退棧,在後面講解了Fragment與Activity通訊以後,會重構上面的程式碼!
2、Fragment與Activity通訊
因為所有的Fragment都是依附於Activity的,所以通訊起來並不複雜,大概歸納為:
a、如果你Activity中包含自己管理的Fragment的引用,可以通過引用直接訪問所有的Fragment的public方法
b、如果Activity中未儲存任何Fragment的引用,那麼沒關係,每個Fragment都有一個唯一的TAG或者ID,可以通過getFragmentManager.findFragmentByTag()或者findFragmentById()獲得任何Fragment例項,然後進行操作。
c、在Fragment中可以通過getActivity得到當前繫結的Activity的例項,然後進行操作。
注:如果在Fragment中需要Context,可以通過呼叫getActivity(),如果該Context需要在Activity被銷燬後還存在,則使用getActivity().getApplicationContext()。
3、Fragment與Activity通訊的最佳實踐
因為要考慮Fragment的重複使用,所以必須降低Fragment與Activity的耦合,而且Fragment更不應該直接操作別的Fragment,畢竟Fragment操作應該由它的管理者Activity來決定。
下面我通過兩種方式的程式碼,分別重構,FragmentOne和FragmentTwo的點選事件,以及Activity對點選事件的響應:
首先看FragmentOne
- package com.zhy.zhy_fragments;
- import android.app.Fragment;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.Button;
- publicclass FragmentOne extends Fragment implements OnClickListener
- {
- private Button mBtn;
- /**
- * 設定按鈕點選的回撥
- * @author zhy
- *
- */
- publicinterface FOneBtnClickListener
- {
- void onFOneBtnClick();
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState)
- {
- View view = inflater.inflate(R.layout.fragment_one, container, false);
- mBtn = (Button) view.findViewById(R.id.id_fragment_one_btn);
- mBtn.setOnClickListener(this);
- return view;
- }
- /**
- * 交給宿主Activity處理,如果它希望處理
- */
- @Override
- publicvoid onClick(View v)
- {
- if (getActivity() instanceof FOneBtnClickListener)
- {
- ((FOneBtnClickListener) getActivity()).onFOneBtnClick();
- }
- }
- }
可以看到現在的FragmentOne不和任何Activity耦合,任何Activity都可以使用;並且我們聲明瞭一個介面,來回調其點選事件,想要管理其點選事件的Activity實現此介面就即可。可以看到我們在onClick中首先判斷了當前繫結的Activity是否實現了該介面,如果實現了則呼叫。
再看FragmentTwo
- package com.zhy.zhy_fragments;
- import android.app.Fragment;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.Button;
- publicclass FragmentTwo extends Fragment implements OnClickListener
- {
- private Button mBtn ;
- private FTwoBtnClickListener fTwoBtnClickListener ;
- publicinterface FTwoBtnClickListener
- {
- void onFTwoBtnClick();
- }
- //設定回撥介面
- publicvoid setfTwoBtnClickListener(FTwoBtnClickListener fTwoBtnClickListener)
- {
- this.fTwoBtnClickListener = fTwoBtnClickListener;
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState)
- {
- View view = inflater.inflate(R.layout.fragment_two, container, false);
- mBtn = (Button) view.findViewById(R.id.id_fragment_two_btn);
- mBtn.setOnClickListener(this);
- return view ;
- }
- @Override
- publicvoid onClick(View v)
- {
- if(fTwoBtnClickListener != null)
- {
- fTwoBtnClickListener.onFTwoBtnClick();
- }
- }
- }
與FragmentOne極其類似,但是我們提供了setListener這樣的方法,意味著Activity不僅需要實現該介面,還必須顯示呼叫mFTwo.setfTwoBtnClickListener(this)。
最後看Activity :
- package com.zhy.zhy_fragments;
- import android.app.Activity;
- import android.app.FragmentManager;
- import android.app.FragmentTransaction;
- import android.os.Bundle;
- import android.view.Window;
- import com.zhy.zhy_fragments.FragmentOne.FOneBtnClickListener;
- import com.zhy.zhy_fragments.FragmentTwo.FTwoBtnClickListener;
- publicclass MainActivity extends Activity implements FOneBtnClickListener,
- FTwoBtnClickListener
- {
- private FragmentOne mFOne;
- private FragmentTwo mFTwo;
- private FragmentThree mFThree;
- @Override
- protectedvoid onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.activity_main);
- mFOne = new FragmentOne();
- FragmentManager fm = getFragmentManager();
- FragmentTransaction tx = fm.beginTransaction();
- tx.add(R.id.id_content, mFOne, "ONE");
- tx.commit();
- }
- /**
- * FragmentOne 按鈕點選時的回撥
- */
- @Override
- publicvoid onFOneBtnClick()
- {
- if (mFTwo == null)
- {
- mFTwo = new FragmentTwo();
- mFTwo.setfTwoBtnClickListener(this);
- }
- FragmentManager fm = getFragmentManager();
- FragmentTransaction tx = fm.beginTransaction();
- tx.replace(R.id.id_content, mFTwo, "TWO");
- tx.addToBackStack(null);
- tx.commit();
- }
- /**
- * FragmentTwo 按鈕點選時的回撥
- */
- @Override
- publicvoid onFTwoBtnClick()
- {
- if (mFThree == null)
- {
- mFThree = new FragmentThree();
- }
- FragmentManager fm = getFragmentManager();
- FragmentTransaction tx = fm.beginTransaction();
- tx.hide(mFTwo);
- tx.add(R.id.id_content, mFThree, "THREE");
- // tx.replace(R.id.id_content, fThree, "THREE");
- tx.addToBackStack(null);
- tx.commit();
- }
- }
程式碼重構結束,與開始的效果一模一樣。上面兩種通訊方式都是值得推薦的,隨便選擇一種自己喜歡的。這裡再提一下:雖然Fragment和Activity可以通過getActivity與findFragmentByTag或者findFragmentById,進行任何操作,甚至在Fragment裡面操作另外的Fragment,但是沒有特殊理由是絕對不提倡的。Activity擔任的是Fragment間類似匯流排一樣的角色,應當由它決定Fragment如何操作。另外雖然Fragment不能響應Intent開啟,但是Activity可以,Activity可以接收Intent,然後根據引數判斷顯示哪個Fragment。
4、如何處理執行時配置發生變化
這裡提一下:很多人覺得強制設定螢幕的方向就可以了,但是有一點,當你的應用被至於後臺(例如使用者點選了home),長時間沒有返回的時候,你的應用也會被重新啟動。比如上例:如果你把上面的例子你至於FragmentThree介面,然後處於後臺狀態,長時間後你會發現當你再次通過home開啟時,上面FragmentThree與FragmentOne疊加在一起,這就是因為你的Activity重新啟動,在原來的FragmentThree上又繪製了一個FragmentOne。
好了,下面看一段程式碼:
Activity:
- package com.zhy.zhy_fragments;
- import android.app.Activity;
- import android.app.FragmentManager;
- import android.app.FragmentTransaction;
- import android.os.Bundle;
- import android.view.Window;
- publicclass MainActivity extends Activity
- {
- private FragmentOne mFOne;
- @Override
- protectedvoid onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.activity_main);
- mFOne = new FragmentOne();
- FragmentManager fm = getFragmentManager();
- FragmentTransaction tx = fm.beginTransaction();
- tx.add(R.id.id_content, mFOne, "ONE");
- tx.commit();
- }
- }
Fragment
- package com.zhy.zhy_fragments;
- import android.app.Fragment;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- publicclass FragmentOne extends Fragment
- {
- privatestaticfinal String TAG = "FragmentOne";
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState)
- {
- Log.e(TAG, "onCreateView");
- View view = inflater.inflate(R.layout.fragment_one, container, false);
- return view;
- }
- @Override
- publicvoid onCreate(Bundle savedInstanceState)
- {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- Log.e(TAG, "onCreate");
- }
- @Override
- publicvoid onDestroyView()
- {
- // TODO Auto-generated method stub
- super.onDestroyView();
- Log.e(TAG, "onDestroyView");
- }
- @Override
- publicvoid onDestroy()
- {
- // TODO Auto-generated method stub
- super.onDestroy();
- Log.e(TAG, "onDestroy");
- }
- }
很簡單的程式碼,當你執行之後,不斷的旋轉螢幕,你會發現每旋轉一次螢幕,螢幕上就多了一個FragmentOne的例項,並且後臺log會打印出許多套生命週期的回撥。
類似:
- 07-20 08:18:46.651: E/FragmentOne(1633): onCreate
- 07-20 08:18:46.651: E/FragmentOne(1633): onCreate
- 07-20 08:18:46.651: E/FragmentOne(1633): onCreate
- 07-20 08:18:46.681: E/FragmentOne(1633): onCreateView
- 07-20 08:18:46.831: E/FragmentOne(1633): onCreateView
- 07-20 08:18:46.891: E/FragmentOne(1633): onCreateView
這是為什麼呢,因為當螢幕發生旋轉,Activity發生重新啟動,預設的Activity中的Fragment也會跟著Activity重新建立;這樣造成當旋轉的時候,本身存在的Fragment會重新啟動,然後當執行Activity的onCreate時,又會再次例項化一個新的Fragment,這就是出現的原因。
那麼如何解決呢:
其實通過檢查onCreate的引數Bundle savedInstanceState就可以判斷,當前是否發生Activity的重新建立:
預設的savedInstanceState會儲存一些資料,包括Fragment的例項:通過列印可以看出:
- 07-2008:23:12.952: E/FragmentOne(1782): Bundle[{android:fragments=android.app.FragmentManagerState@40d0b7b8, android:viewHierarchyState=Bundle[{android:focusedViewId=2131230721, android:views=android.util.SparseArray@40d0af68}]}]
- package com.zhy.zhy_fragments;
- import android.app.Activity;
- import android.app.FragmentManager;
- import android.app.FragmentTransaction;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Window;
- publicclass MainActivity extends Activity
- {
- privatestaticfinal String TAG = "FragmentOne";
- private FragmentOne mFOne;
- @Override
- protectedvoid onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.activity_main);
- Log.e(TAG, savedInstanceState+"");
- if(savedInstanceState == null)
- {
- mFOne = new FragmentOne();
- FragmentManager fm = getFragmentManager();
- FragmentTransaction tx = fm.beginTransaction();
- tx.add(R.id.id_content, mFOne, "ONE");
- tx.commit();
- }
- }
- }
現在無論進行多次旋轉都只會有一個Fragment例項在Activity中。
現在還存在一個問題,就是重新繪製時,Fragment發生重建,原本的資料如何保持?
其實和Activity類似,Fragment也有onSaveInstanceState的方法,在此方法中進行儲存資料,然後在onCreate或者onCreateView或者onActivityCreated進行恢復都可以。
由於篇幅原因,就不貼測試程式碼了。
5、Fragmeny與ActionBar和MenuItem整合
Fragment可以新增自己的MenuItem到Activity的ActionBar或者可選選單中。
a、在Fragment的onCreate中呼叫setHasOptionsMenu(true);
b、然後在Fragment子類中實現onCreateOptionsMenu
c、如果希望在Fragment中處理MenuItem的點選,也可以實現onOptionsItemSelected;當然了Activity也可以直接處理該MenuItem的點選事件。
程式碼:
Fragment
- package com.zhy.zhy_fragments;
- import android.app.Fragment;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Toast;
- publicclass FragmentOne extends Fragment
- {
- @Override
- publicvoid onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState)
- {
- View view = inflater.inflate(R.layout.fragment_one, container, false);
- return view;
- }
- @Override
- publicvoid onCreateOptionsMenu(Menu menu, MenuInflater inflater)
- {
- inflater.inflate(R.menu.fragment_menu, menu);
- }
- @Override
- publicboolean onOptionsItemSelected(MenuItem item)
- {
- switch (item.getItemId())
- {
- case R.id.id_menu_fra_test:
- Toast.makeText(getActivity(), "FragmentMenuItem1", Toast.LENGTH_SHORT).show();
- break;
- }
- returntrue;
- }
- }
Activity
- package com.zhy.zhy_fragments;
- import android.app.Activity;
- import android.app.FragmentManager;
- import android.app.FragmentTransaction;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.Window;
- import android.widget.Toast;
- publicclass MainActivity extends Activity
- {
- privatestaticfinal String TAG = "FragmentOne";
- private FragmentOne mFOne;
- @Override
- protectedvoid onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.activity_main);
- Log.e(TAG, savedInstanceState + "");
- if (savedInstanceState == null)
- {
- mFOne = new FragmentOne();
- FragmentManager fm = getFragmentManager();
- FragmentTransaction tx = fm.beginTransaction();
- tx.add(R.id.id_content, mFOne, "ONE");
- tx.commit();
- }
- }
- @Override
- publicboolean onCreateOptionsMenu(Menu menu)
- {
- super.onCreateOptionsMenu(menu);
- getMenuInflater().inflate(R.menu.main, menu);
- returntrue;
- }
- @Override
- publicboolean onOptionsItemSelected(MenuItem item)
- {
- switch (item.getItemId())
- {
- case R.id.action_settings:
- Toast.makeText(this, "setting", Toast.LENGTH_SHORT).show();
- returntrue;
- default:
- //如果希望Fragment自己處理MenuItem點選事件,一定不要忘了呼叫super.xxx
- returnsuper.onOptionsItemSelected(item);
- }
- }
- }
效果圖:
好了,可以很好的看到,Fragment可以新增MenuItem,也可以自己處理點選~~~
6、沒有佈局的Fragment的作用
沒有佈局檔案Fragment實際上是為了儲存,當Activity重啟時,儲存大量資料準備的
7、使用Fragment建立對話方塊
相關推薦
Android Fragment 真正的完全解析(下)
上篇部落格中已經介紹了Fragment產生原因,以及一些基本的用法和各種API,如果你還不瞭解,請看:Android Fragment 真正的完全解析(上)。 本篇將介紹上篇部落格提到的:如何管理Fragment回退棧,Fragment如何與Activity互動,Frag
Android N App分屏模式完全解析(下)
在上篇中,介紹了什麼是App分屏模式,以及如何設定我們的App來進入分屏模式。這次我們看一下,作為開發者,我們應該如何讓自己的App進入分屏模式,當App進入分屏模式時,我們注意哪些問題。 簡單地說,我認為除了保證分屏時App功能、效能正常以外,我們需要重點學習 如何在分屏模式下開啟新的Activity 以
Android安全攻防戰,反編譯與混淆技術完全解析(下)
http://blog.csdn.net/guolin_blog/article/details/50451259 http://blog.csdn.net/guolin_blog/article/details/50451259 http://blog.csdn
Android Fragment 真正的完全解析(上)
watermark 展示 near 主界面 ddt comm 講解 超級 pro 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/lmj623565791/article/details/37970961 轉載請標明出處:
轉Android Fragment 真正的完全解析(上)
自從Fragment出現,曾經有段時間,感覺大家談什麼都能跟Fragment談上關係,做什麼都要問下Fragment能實現不~~~哈哈,是不是有點過~~~ 本篇部落格力求為大家說明Fragment如何產生,什麼是Fragment,Fragment生命週期,如何靜態和動態的使用Fragment,Fra
Android Fragment 從原始碼的角度去解析(下)
1.概述 上一篇部落格已經簡單的講了一下Fragment的使用並寫了一個基本的例項,接下來就將其整合到專案中。附視訊地址:http://pan.baidu.com/s/1mhUus56 2.效果實現
Android 屬性動畫(Property Animation) 完全解析 (上)【轉】
轉載請標明出處:http://blog.csdn.net/lmj623565791/article/details/38067475 1、概述 Android提供了幾種動畫型別:View Animation 、Drawable Animation 、Property Anima
【Android自助餐】Handler訊息機制完全解析(二)MessageQueue的佇列管理
Android自助餐Handler訊息機制完全解析(二)MessageQueue的佇列管理 Android自助餐Handler訊息機制完全解析二MessageQueue的佇列管理 新增到訊息佇列enqueueMessage 從佇
【Android自助餐】Handler訊息機制完全解析(五)鳥瞰與總結
Android自助餐Handler訊息機制完全解析(五)鳥瞰與總結 Android自助餐Handler訊息機制完全解析五鳥瞰與總結 Message MessageQueue Handler Looper
【Android自助餐】Handler訊息機制完全解析(四)Looper解析
Android自助餐Handler訊息機制完全解析(四)Looper解析 Android自助餐Handler訊息機制完全解析四Looper解析 Looper 初始化prepare 提供loope
Android進階——效能優化之程序拉活原理及手段完全解析(二)
引言 上一篇文章Android進階——效能優化之程序保活原理及手段完全解析(一)總結了Android程序和執行緒的相關知識,主要介紹了幾種提升程序優先順序的手段,通常僅僅是提高優先順序只能讓你的程序存活時間久一點,但是真正的被殺死之後就不會自動拉活的,如果你的程
Android 開源框架Universal-Image-Loader完全解析(一)--- 基本介紹及使用
大家好!差不多兩個來月沒有寫文章了,前段時間也是在忙換工作的事,準備筆試面試什麼的事情,現在新工作找好了,新工作自己也比較滿意,唯一遺憾的就是自己要去一個新的城市,新的環境新的開始,希望自己能儘快的適應新環境,現在在準備交接的事情,自己也有一些時間了,所以就繼續給大家分享And
Android安全攻防戰,反編譯與混淆技術完全解析(上)
轉載請註明出處:http://blog.csdn.net/guolin_blog/article/details/49738023 之前一直有猶豫過要不要寫這篇文章,畢竟去反編譯人家的程式並不是什麼值得驕傲的事情。不過單純從技術角度上來講,掌握反編譯功能確實是
Android 屬性動畫(Property Animation) 完全解析 (上)
目錄(?)[+] 1、概述 Android提供了幾種動畫型別:View Animation 、Drawable Animation 、Property Animation 。View Animation相當簡單,不過只能支援簡單的縮放、平移、旋轉、透明度基本的動畫,
Android 網路通訊框架Volley完全解析(一)
Volley簡介及Request基本用法 Google I/O 2013上,Volley釋出了。Volley是Android平臺上的網路通訊庫,能使網路通訊更快,更簡單,更健壯。這是Volley名
Android硬編解碼介面MediaCodec使用完全解析(一)
由於4月初要離職了,在找新工作,發現很多企業的招聘資訊都有“附上自己的技術部落格可以加分”類似的說明,正好最後的這段時間會比較閒,所以打算整理一下以前記錄的一些筆記發上來,也算是回顧一下。由於這些筆記或多或少的參考了其他資料,所以本人不擁有其版權,可以隨便
Android 開源框架Universal-Image-Loader完全解析(二)--- 圖片快取策略詳解
本篇文章繼續為大家介紹Universal-Image-Loader這個開源的圖片載入框架,介紹的是圖片快取策略方面的,如果大家對這個開源框架的使用還不瞭解,大家可以看看我之前寫的一篇文章Android 開源框架Universal-Image-Loader完全解析(一)---
android permission許可權與安全機制解析(下)
剛建了一個QQ群,感興趣的大家一起多多交流:544645972 在android permission許可權與安全機制解析(上)篇部落格中,我已經詳細介紹了android相關係統permission和自定義permission,以及一些許可權機制和安全
Android Activity 完全解析(中)
在上一篇文章中我們學習了 Activity 的生命週期以及用 Intent 開啟系統的方法相關方面的知識,分析了單個 Activity 生命週期從建立到銷燬的過程,以及多個 Activit
Lambda表達式樹解析(下)
equal arguments provider inf gets 轉換 lis bin text 概述 前面章節,總結了Lambda樹的構建,那麽怎麽解析Lambda表達式樹那?Lambda表達式是一種委托構造而成,如果能夠清晰的解析Lambda表達式樹,那麽就能夠