(1).Toast能在许多的Activity看到, 使用 getapplicationContext() (2).service经常比activity生命周期长,所以使用如下的代码:
Intent myService = new Intent(getApplicationContext(), MyService.class)
下图展示了哪些场合使用Contexts时合适的
例如使用Google位置service,但是忘记调用googleApiClient.disconnect()来关闭
//Disconnect from API onDestroy() if (googleApiClient.isConnected()) { LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, GoogleLocationService.this); googleApiClient.disconnect(); }如果你使用Square’s 的第三方库 Picasso, 我发现如果不调用.fit()会造成内存泄漏, 这个函数把我的内存从50M减少到少于19M
Picasso.with(ActivityExample.this) //Activity context .load(object.getImageUrl()) .fit() //This avoided the OutOfMemoryError .centerCrop() //makes image to not stretch .into(imageView);使用 broadcast receivers要解除注册
如果你使用 java.util.Observer (Observer pattern):
确认调用 deleteObserver(observer);
普照天星【Java开发工程师】20-30k http://www.jianshu.com/p/8b52751360df 产品经理20-30k http://www.jianshu.com/p/cb0ac7a00796


新闻热点
疑难解答