android.app.serviceconnectionleaked与mysql连接时

时间:2013-09-26 14:52:06

标签: java android mysql

我在没有任何服务器帮助的情况下直接连接mysql数据库。当我尝试使用模拟器连接mysql时,它工作正常。但是当我使用我的手机时,它会抛出一些异常。我不知道是什么问题。请帮帮我。

这是我的代码:

Connection con;
PreparedStatement ps;
Statement st;
ResultSet rs;
String val = "";
Context cont = this;
View menuItemView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Thread on=new Thread(){
        @Override
        public void run(){
          Log.i("Thread","Running"); 
            try {
                    Class.forName("com.mysql.jdbc.Driver");
                    Log.i("Connection","connected with jdbc");
                    con = DriverManager.getConnection("jdbc:mysql://192.168.1.2:3306/outsidelaundry", "vino" , "vino");
                    Log.i("Connection","connected with database");
                    runOnUiThread(new Runnable() {
                        @Override 
                        public void run() {
                                Toast.makeText(getApplicationContext(), "connected", Toast.LENGTH_LONG).show();
                        }
                    });
            } catch (Exception e) {
                e.printStackTrace();

            }
        }
    };
    on.start();
}

logcat错误说:

09-26 14:46:05.474: E/StrictMode(809): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cec370 that was originally bound here
09-26 14:46:05.474: E/StrictMode(809):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
09-26 14:46:05.474: E/StrictMode(809):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
09-26 14:46:05.474: E/StrictMode(809):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
09-26 14:46:05.474: E/StrictMode(809):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
09-26 14:46:05.474: E/StrictMode(809):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
09-26 14:46:05.474: E/StrictMode(809):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
09-26 14:46:05.474: E/StrictMode(809):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-26 14:46:05.474: E/StrictMode(809):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
09-26 14:46:05.474: E/StrictMode(809):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-26 14:46:05.474: E/StrictMode(809):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-26 14:46:05.474: E/StrictMode(809):  at java.lang.Thread.run(Thread.java:856)
09-26 14:46:05.484: W/ActivityManager(339): Unbind failed: could not find connection for android.os.BinderProxy@4102be08

解决方案:我找到了解决此问题的方法。为了将您的移动设备与mysql数据库直接连接以发送/接收数据,您应首先在wifi上进行,不仅如此,还要在设备中启用后台数据和自动同步。背景数据是允许在设备内传播数据的数据。

1 个答案:

答案 0 :(得分:-1)

我可能不记得这个。我认为解决方案是将此问题添加到Application

,我遇到了类似的问题
@Override
public void onCreate() {
    try {
        Class.forName("android.os.AsyncTask");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    super.onCreate();
}