Android的凹凸阿比网络上的主线程异常 [英] Android Bump Api Network on main thread exception

查看:115
本文介绍了Android的凹凸阿比网络上的主线程异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我很新的Andr​​oid和Java的世界(从C / C ++ / Objective-C的推出)。
我试图在Android凹凸API(3.0,最新的版本)集成,但我遇到麻烦了。
我复制为例,它的Andr​​oid 2.2下工作正常,磕碰服务正确启动,但是对于Android的3.0和上它没有工作。
我有一个例外(在主线程之一网)我加载活动时,我知道这个例外,如何避免它,但在这种情况下,凹凸状态,他们运行他们的API在自己的线程,所以我不真的知道为什么我得到了它。他们说,你并不需要运行一个线程或任务。

First of all, I'm quite new to the Android and JAVA world (coming from C/C++/Objective-C). I'm trying to integrate the Android bump API (3.0, latest version) but I'm running into trouble. I copied the exemple, it is working fine under Android 2.2, bump services are started correctly, but as for Android 3.0 and upper it does not works. I've got an exception (the network on main thread one) when loading my activity, I know this exception and how to avoid it, but in this case, Bump state that they run their API in their own thread so I don't really know why I got it. They said that you don't need to run a thread or tasks.

下面是我的活动的一个样本

Here is a sample of my Activity

public class BumpActivity extends Activity {
private IBumpAPI api;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bump);

    bindService(new Intent(IBumpAPI.class.getName()), connection,
            Context.BIND_AUTO_CREATE);

    IntentFilter filter = new IntentFilter();
    filter.addAction(BumpAPIIntents.CHANNEL_CONFIRMED);
    filter.addAction(BumpAPIIntents.DATA_RECEIVED);
    filter.addAction(BumpAPIIntents.NOT_MATCHED);
    filter.addAction(BumpAPIIntents.MATCHED);
    filter.addAction(BumpAPIIntents.CONNECTED);
    registerReceiver(receiver, filter);



}


@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

private final ServiceConnection connection = new ServiceConnection() {
    @Override
    public void onServiceConnected(ComponentName className, IBinder binder) {

        Log.i("BumpTest", "onServiceConnected");
        api = IBumpAPI.Stub.asInterface(binder);
        try {
            api.configure("API_KEY", "Bump User");
        } catch (RemoteException e) {
            Log.w("BumpTest", e);
        }
        Log.d("Bump Test", "Service connected");
    }

    @Override
    public void onServiceDisconnected(ComponentName className) {
        Log.d("Bump Test", "Service disconnected");
    }
};
}

在api.configure连接服务过程中出现类似问题的声音....
我应该在一个单独的线程或它自己的运行AsynchTask,但再怎么,为什么?

Sound like the problem occur during the connection service on the api.configure.... Should I run it in a separate thread or in it's own AsynchTask, but then how and why ?

推荐答案

我被困在这个问题一天左右...和文采在这里张贴2分钟后我解决它...
我只是把api.configure一个单独的线程(比AsynchTask短)。

I stuck on this problem for a day or so... and literarily 2 minutes after posting it here I resolved it... I just put the api.configure on a separate thread (shorter than a AsynchTask).

private final ServiceConnection connection = new ServiceConnection() {
    @Override
    public void onServiceConnected(ComponentName className, IBinder binder) {

        Log.i("BumpTest", "onServiceConnected");
        api = IBumpAPI.Stub.asInterface(binder);
        new Thread() {
            public void run() {
                try {
                    api.configure("API_KEY",
                            "Bump User");
                } catch (RemoteException e) {
                    Log.w("BumpTest", e);
                }

            }
        }.start();

        Log.d("Bump Test", "Service connected");
    }

    @Override
    public void onServiceDisconnected(ComponentName className) {
        Log.d("Bump Test", "Service disconnected");
    }
};

这篇关于Android的凹凸阿比网络上的主线程异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆