我只是写一个活动使用Kotlin,它的样本很简单,代码如下:
package com.chiquedoll.chiquedoll.view.activity
import android.os.Bundle
import com.chiquedoll.chiquedoll.R
import kotlinx.android.synthetic.main.view_normal_toolbar.*
/**
* Created by super-zuo on 17-12-12.
* Description:
*/
class TestActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_edit_profile)
tv_title.text = getString(R.string.edit_profile)
tv_right.text = getString(R.string.save)
}
}
这是我的BaseActivity代码:
public class BaseActivity extends AppCompatActivity {
private ActivityModule activityModule;
private ViewDataBinding indicatorBinding;
private ProgressDialog dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
BaseApplication.mSession = (MSession) savedInstanceState.getSerializable("mSession");
if (BaseApplication.mSession != null && BaseApplication.mSession.customer != null) {
HeadInterceptor.setUserId(BaseApplication.mSession.customer.id);
HeadInterceptor.setAccessToken(BaseApplication.mSession.getAccessToken());
}
}
getApplicationComponent().inject(this);
}
protected ApplicationComponent getApplicationComponent() {
return ((BaseApplication) getApplication()).getApplicationComponent();
}
protected ActivityModule getActivityModule() {
if (activityModule == null) {
return new ActivityModule(this);
}
return activityModule;
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState != null) {
BaseApplication.mSession = (MSession) savedInstanceState.getSerializable("mSession");
if (BaseApplication.mSession != null && BaseApplication.mSession.customer != null) {
HeadInterceptor.setUserId(BaseApplication.mSession.customer.id);
HeadInterceptor.setAccessToken(BaseApplication.mSession.getAccessToken());
}
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
Log.e("SaveInstanceState", "yes");
outState.putSerializable("mSession", BaseApplication.mSession);
super.onSaveInstanceState(outState);
}
}
当我关闭活动时,LeakCanary告诉我活动已经泄露。有人能帮帮我吗?当我使用EditText时,TextInputEditText也会泄漏Activity。