我制作了一个闪屏,然后像往常一样开始活动。
但是我注意到即使我完成了活动,内存使用量也增加了很多,并且在使用背景的闪存和没有背景的闪存之间的内存使用量存在很大差异。
对此有何解决方案?
当splash没有背景图像时捕获内存
当splash具有背景图像时捕获内存
启动活动的代码
public class SplashActivity extends AppCompatActivity {
/**
* To get ride of the activity reference to avoid memory leaks
*/
private static WeakReference<SplashActivity> mActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
mActivity = new WeakReference<>(this);
//delay for 2 seconds and start the home activity
Completable.complete()
.delay(2, TimeUnit.SECONDS)
.doOnComplete(this::startHomeActivity)
.subscribe();
}
private void startHomeActivity() {
if (mActivity.get() != null) {
Activity activity = mActivity.get();
Intent homeIntent = new Intent(activity, HomeActivity.class);
startActivity(homeIntent);
activity.finish();
}
}
}
并在清单
中设置主题<style name="splashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/zamen_splash</item>
<item name="colorPrimaryDark">@color/splash_color_dark</item>
</style>
答案 0 :(得分:3)