Android 活动已泄漏,但无法修复

Android 活动已泄漏,但无法修复,android,memory-leaks,leakcanary,Android,Memory Leaks,Leakcanary,我用LeakCanary来测试我的应用程序。它有漏洞,但我修不好 public class SplashActivity extends Activity { private TextView splashTime; private Long showTime; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setConte

我用LeakCanary来测试我的应用程序。它有漏洞,但我修不好

public class SplashActivity extends Activity {

private TextView splashTime;
private Long showTime;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_splash);
    init();
}

public void init() {
    showTime = 1L;
    splashTime = (TextView) findViewById(R.id.splash_time);
    splashTime.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            enterApp();
        }
    });
    splashTime.setText(getString(R.string.splash_time, showTime));
    Log.d("splash", "init");
}

public void enterApp() {
    Intent intent = new Intent(this, HomeActivity.class);
    startActivity(intent);
    finish();
}}
金丝雀日志在这里:

D/LeakCanary: In com.less.haku.hcomic:1.0:1.
                 * com.less.haku.hcomic.SplashActivity has leaked:
                 * GC ROOT static android.app.Instrumentation.mRecommendActivity
                 * references android.app.Instrumentation$RecommendActivity.mTarget
                 * leaks com.less.haku.hcomic.SplashActivity instance

                 * Reference Key: f4ea7ad3-a212-439f-ba67-3557823b07e9
                 * Device: Meizu Meizu m2 note m2 note
                 * Android Version: 5.1 API: 22
                 * Durations: watch=5014ms, gc=176ms, heap dump=2598ms, analysis=23065ms
我不知道它是如何发生的,活动非常简单,没有处理程序,没有内部类。我不懂canaryLog,如何追踪问题?谢谢你的帮助


我使用string.xml连接字符串。所有string.xml代码都在这里:

<resources>
<string name="app_name">HComic</string>
<string name="action_settings">Settings</string>
<string name="splash_time">less %1$ds</string>
</resources>

色情漫画
设置
少于%1$ds
SplashActivity是清单代码中的第一个活动:

<activity
        android:screenOrientation="portrait"
        android:name=".SplashActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


我在很多情况下都测试过这个,可能是我的手机造成的,它在模拟器中没有泄漏,我会在其他一些安卓手机上测试。

这是魅族FlymeOS中的一个bug。把它排除在外。详情请参阅我的

如果您无法等待合并此PR,您可以执行以下操作以排除此泄漏:

ExcludedRefs excludedRefs = AndroidExcludedRefs.createAppDefaults()
            .staticField("android.app.Instrumentation", "mRecommendActivity")
            .reason("Instrumentation would leak com.android.internal.app.RecommendActivity (in framework.jar) in Meizu FlymeOS")
            .build();
LeakCanary.install(application, DisplayLeakService.class, excludedRefs);

使用
getString(R.string.splash_-time)
时会发生什么?问题在于
splashTime.setText(getString(R.string.splash_-time,showTime))
getString(R.string.splash\u time,showTime)
中显示您的代码我使用string.xml连接字符串。所有string.xml代码都在这里:HComic设置小于%1$ds可能问题出在SplashActivity的调用中。谁叫SplashActivity?