android 学习
Handler 使用
Bundle bundleData = Algorithm(location); if (bundleData != null) { LocationHandler locationHandler = new LocationHandler(MapActivity.this); Message locationMsg = locationHandler.obtainMessage(); bundleData.putParcelable("location", location); locationMsg.setData(bundleData); locationHandler.sendMessage(locationMsg); } ``` ## Handler 弱引用处理内存泄漏 ```java public static class LocationHandler extends Handler { WeakReference<MapActivity> mActivity; LocationHandler(MapActivity activity) { mActivity = new WeakReference<>(activity); } @Override public void handleMessage(Message msg) { MapActivity activity = mActivity.get(); if (activity != null) { // TODO: 2019年4月17日 } } }