Why onCreate() calling multiple times when i use Thread()?

Posted by RajaReddy PolamReddy on Stack Overflow See other posts from Stack Overflow or by RajaReddy PolamReddy
Published on 2012-11-08T10:34:21Z Indexed on 2012/11/08 11:01 UTC
Read the original article Hit count: 166

In my app i faced a problem with threads. i am using native code in my app. i try to load library and then calling native functions from the android code.

1. By using Threads() :

PjsuaThread pjsuaThread = new PjsuaThread();
pjsuaThread.start();

thread code

class PjsuaThread extends Thread {  

    public void run() {
        if (pjsua_app.initApp() != 0) { // native function calling           
            return;
        } else {                 
        }
        pjsua_app.startPjsua(ApjsuaActivity.CFG_FNAME); // native function calling
        finished = true;         
    }

When i use code like this, onCreate() function calling multiple times and able to load library and calling some functions properly, after some seconds onCreate calling again because of that it's crashing.

2. Using AsyncTask():

And also i used AsyncTask<> for this requirement, it's crashing the application( crashing in lib code ). not able to open any functions

class SipTask extends AsyncTask<Void, String, Void> {       
    protected Void doInBackground(Void... args) {           

        if (pjsua_app.initApp() != 0) {             
            return null;
        } else {                
        }
        pjsua_app.startPjsua(ApjsuaActivity.CFG_FNAME);
        finished = true;
        return null;
    }   

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        Log.i(TAG, "On POst ");
    }
}

What is annoying is that in most cases it is not the missing library, it's tried to able to load the lib crashing in between. any one know the reason ?

© Stack Overflow or respective owner

Related posts about android

Related posts about multithreading