Does an Android service lock the app even when running in the background? [closed]

2

Does an Android service crash the app even while running in the background? Or is there something wrong with my application?

I have a database where the last table has 3000 rows. With this I decided to insert in the background using a service to give faster time to the user at the time of insertion. But this service is crashing my application, and only releases my application when the Thread inserts all the data in the database.

Does anyone know what it can be? Follow the code.

public class ServiceAndroid extends Service{

    Thread thread;

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();       

    }


    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        Toast.makeText(getApplicationContext(), "iniciou o service", Toast.LENGTH_LONG).show();


        thread = new Thread(){
            public void run(){
                try {
                    //meu código
                } catch (ClassNotFoundException | IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }       
        };
        thread.start();

        return START_STICKY;
    }


}

method where I call the service:

// inicia o service
   public void startService(View view){

       Intent i = new Intent(getBaseContext(), ServiceAndroid.class);
       startService(i);
   }
    
asked by anonymous 09.11.2015 / 20:16

0 answers