編輯:關於 Android 開發

Module → Component → Application。首先建立模塊(Module)提供所需的類實例,其次把模塊加入組件(Component)並提供需要注入的類,最後把組件加入應用(Application)並提供介面。
// 模塊
@Module
public class TestAppModule {
private final Context mContext;
public TestAppModule(Context context) {
mContext = context.getApplicationContext();
}
@AppScope
@Provides
public Context provideAppContext() {
return mContext;
}
@Provides
public WeatherApiClient provideWeatherApiClient() {
return new MockWeatherApiClient();
}
}
// 組件
@AppScope
@Component(modules = TestAppModule.class)
public interface TestAppComponent extends AppComponent {
void inject(MainActivityTest test);
}
// 應用
public class TestWeatherApplication extends WeatherApplication {
private TestAppComponent mTestAppComponent;
@Override
public void onCreate() {
super.onCreate();
mTestAppComponent = DaggerTestAppComponent.builder()
.testAppModule(new TestAppModule(this))
.build();
}
@Override
public TestAppComponent getAppComponent() {
return mTestAppComponent;
}
}
Android 調試工具,不需重新編譯即可刷新部分項目修改。不過這個功能已被 Android Studio 2.0 的 Instant Run 取代,可等待 2.0 正式發版。
DataBinding 實現數據與頁面的分離,更符合面向對象的編程模式。布局中透過 variable 宣告數據物件,並以 @{...} 語法綁定:
<data>
<variable name="weatherData" type="clwang.chunyu.me.wcl_espresso_dagger_demo.data.WeatherData" />
</data>
<TextView
android:id="@+id/temperature"
android:text="@{weatherData.temperatureCelsius}"
... />
邏輯中則用生成的綁定類:
private ActivityMainBinding mBinding; mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); mBinding.weatherLayout.setVisibility(View.VISIBLE); // 使用 Id mBinding.setWeatherData(weatherData); // 綁定數據
查看 Apk 資訊的強大工具,省去反編譯步驟,主要功能包括:查看 MultiDex 中 dex 的詳細資訊、NativeLibrary 資訊、類的詳細資訊,以及各項數量統計。
升級 Mac 系統後可能導致 Pod 命令消失,需要重新安裝:
sudo gem install -n /usr/local/bin cocoapods
LaunchMode 共四種:
(1) standard:標準模式,每次啟動都重建實例,為預設值。
(2) singleTop:棧頂複用模式,若位於棧頂則不會重建,改為呼叫 onNewIntent。
(3) singleTask:棧內複用模式,若已存在則不重建,呼叫 onNewIntent。
(4) singleInstance:單實例模式,單獨位於一個任務棧內,會被複用。
OK, that's all. Enjoy it!
Android 網絡編程(四):深入源碼剖析 Volley 工作流程
Android 網絡編程(四):深入源碼剖析 Volley 工作流程 Volley 是 Google 推出的網絡請求庫,以其簡潔的 API 著稱。本文從源碼出發,剖析它的
Android 5.x Notification 完全解析:普通、折疊與懸掛式通知
Android 5.x Notification 完全解析:普通、折疊與懸掛式通知 想像一下,如果沒有 Notification,我們的 QQ、微信與其他應用就無法主動通
用代碼動態修改 Android View 尺寸的實戰做法
用代碼動態修改 Android View 尺寸的實戰做法 我們平時開發時,View 的寬高與位置大多直接在 Layout 的 XML 裡寫死。那麼什麼場景下非得跑到代碼裡
ListView 效能優化的三次進化:從 ViewHolder 到 ViewHolderHelper
ListView 效能優化的三次進化:從 ViewHolder 到 ViewHolderHelper ListView 在滾動時之所以容易卡頓,根源往往不在資料量,而在「