gpt4 book ai didi

android - 数据库的 SQLiteConnection 对象被泄露

转载 作者:行者123 更新时间:2023-11-29 19:17:50 25 4
gpt4 key购买 nike

我是 Android 程序的初学者,遇到以下错误,尝试过提供的解决方案,例如在模拟器上清除 Google Play 商店数据仍然遇到相同的错误,没有使用任何数据库连接代码,但获取的数据库已泄漏,任何帮助将不胜感激。

Error

03-25 17:16:41.664 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:16:41.669 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:16:41.671 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:20:42.080 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:20:42.082 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:20:42.376 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.


Activity A.java
package com.lifecycle.activity.demo.activity_lifecycle;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class ActivityA extends AppCompatActivity {

Button btt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btt = (Button) findViewById(R.id.button);
btt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(ActivityA.this, ActivityB.class);
startActivity(i);
}
});
Log.i("Activity A","onCreate");
}

@Override
protected void onStart() {
super.onStart();
Log.i("Activity A","onStart");
}

@Override
protected void onResume() {
super.onResume();
Log.i("Activity A","onResume");
}

@Override
protected void onPause() {
super.onPause();
Log.i("Activity A","onPause");
}

@Override
protected void onStop() {
super.onStop();
Log.i("Activity A","onStop");
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.i("Activity A","onDestroy");
}

@Override
protected void onRestart() {
super.onRestart();
Log.i("Activity A","onRestart");
}
}

ActivityB.java
package com.lifecycle.activity.demo.activity_lifecycle;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

/**
* Created by karthicklove on 25/03/17.
*/

public class ActivityB extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
Log.i("Activity B","onCreate");
}

@Override
protected void onStart() {
super.onStart();
Log.i("Activity B","onStart");
}

@Override
protected void onResume() {
super.onResume();
Log.i("Activity B","onResume");
}

@Override
protected void onPause() {
super.onPause();
Log.i("Activity B","onPause");
}

@Override
protected void onStop() {
super.onStop();
Log.i("Activity B","onStop");
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.i("Activity B","onDestroy");
}

@Override
protected void onRestart() {
super.onRestart();
Log.i("Activity B","onRestart");
}
}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.lifecycle.activity.demo.activity_lifecycle.ActivityA">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_name1"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="134dp"
android:layout_marginTop="216dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="134dp" />
</android.support.constraint.ConstraintLayout>
activity_b.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/activity_b" />
</LinearLayout>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lifecycle.activity.demo.activity_lifecycle">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ActivityA">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ActivityB"></activity>
</application>

</manifest>

最佳答案

我认为您观察到的不是来自您的应用,而是来自 GMS 服务:

03-25 17:16:41.664 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:16:41.669 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:16:41.671 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:20:42.080 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:20:42.082 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
03-25 17:20:42.376 2335-2344/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.

如果显示的包来自您的应用程序

com.lifecycle.activity.demo.activity_lifecycle

关于android - 数据库的 SQLiteConnection 对象被泄露,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43016812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com