-1

I tried the same questions in stackoverflow but none of them are working.Someone please help me. this is my code

 new Thread(new Runnable() {
                        public void run() {

                            try{
                                CallSoap cs;
                                cs=new CallSoap();
                               // String resp=cs.Call();
                               String resp= cs.Call();
                                ActivateDecive.rslt=resp;
                            }catch(Exception ex)
                            {ActivateDecive.rslt=ex.toString();}  


                            if(ActivateDecive.rslt=="0"||ActivateDecive.rslt.equals("0"))
                             {
                                 //Toast.makeText(getBaseContext(), "Device is not in active state..Please contact admin",Toast.LENGTH_LONG).show();
                                ActivationText.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        // TODO Auto-generated method stub
                                        ActivationText.setText("Device is not in active state..Please contact admin");
                                    }
                                });

                             }
                             else
                             {
                                 Handler handler = new Handler(Looper.getMainLooper());
                                 handler.postDelayed(new Runnable() {

                                        @Override
                                        public void run() {
                                            // TODO Auto-generated method stub
                                            ActivationText.setText("Device is Active");
                                            Intent i=new Intent(ActivateDecive.this,FormSelectionACT.class);

                                            startActivity(i);
                                        }
                                    }, 2000);

                             }

                        }
                    }).start();

Activity is not comming on top only the included layout is showing...

Abhi
  • 101
  • 1
  • 4
  • 11
  • Any LogCat you can show? Also have you looked at runOnUiThread, see if that's applicable to you? – TMH Jun 30 '14 at 08:44
  • thank you for answering..ya i tried ...but still its not working....there is no reeor in logcat. – Abhi Jun 30 '14 at 08:48

2 Answers2

1

Finish your Handler method by adding:

   ActivateDecive.this.finish();

below

 startActivity(i);
0

You have to start the Activity from Main Thread. Do it like this:

Handler handler = new Handler(Looper.getMainLooper());

handler.post(new Runnable() {
    @Override
    public void run() {
        Intent intent = new Intent (MyActivity.this, NextActivity.class);
        startActivity(intent);
    }
});

taken from here: How to start an activity from a thread class in android?

edit Otherwise try to set the handler variable to global, so it should look like this.

 public class MyActivity extends Activity
{
    Handler hander = new Handler(){
        public void handleMessage(Message m){
            Intent intent = new Intent (MyActivity.this, Next.class);
            startActivity(intent);
        }
    };
    pubilc void onCreate(Bundle ic)
    {
       //your code setContentView() etc....
       Thread toRun = new Thread()
       {
              public void run()
              {
                    hander.sendMessage(1); 
              }
       }
       toRun.start();
    }
}
Community
  • 1
  • 1
mapodev
  • 988
  • 8
  • 14