Androyds
Androyds

Reputation: 67

ProgressDialog and TabGroup

I've created a ProgressDialog to show when the user click on a button.

My activity by the way is inside a Tabgroup

Here is my code on ProgressDialog

final ProgressDialog myPd_ring=ProgressDialog.show(MainActivity.this, "Please wait", "Loading please wait..", true);
        myPd_ring.setCancelable(false);
        new Thread(new Runnable() {  
              public void run() {
                    // TODO Auto-generated method stub
                    try 
                    { 
                         //Some data binding here....
                    }catch(Exception e){

                    } 
                    myPd_ring.dismiss();
                    Intent edit = new Intent(getDialogContext(), MerchantActivity.class);
                    TabGroupActivity parentsActivity = (TabGroupActivity)getParent();
                    parentsActivity.startChildActivity("MerchantActivity", edit);
              }
        }).start();

Now everything works fine until when I use the intent. I am getting an error

Here is my LogCat:

10-17 16:35:21.429: E/AndroidRuntime(11604): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mobileoptima.perxclub/com.mobileoptima.perxclub.MerchantActivity}: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at com.mobileoptima.perxclub.TabGroupActivity.startChildActivity(TabGroupActivity.java:55)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at com.mobileoptima.perxclub.CardsActivity$2.run(CardsActivity.java:318)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at java.lang.Thread.run(Thread.java:1019)
10-17 16:35:21.429: E/AndroidRuntime(11604): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.os.Handler.<init>(Handler.java:121)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.Activity.<init>(Activity.java:680)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at com.mobileoptima.perxclub.MerchantActivity.<init>(MerchantActivity.java:63)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at java.lang.Class.newInstanceImpl(Native Method)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at java.lang.Class.newInstance(Class.java:1409)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-17 16:35:21.429: E/AndroidRuntime(11604):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
10-17 16:35:21.429: E/AndroidRuntime(11604): 
... 6 more

Why Am I getting that error? As far as I am concerned I call the parent. Please Help??

Upvotes: 1

Views: 123

Answers (2)

Androyds
Androyds

Reputation: 67

Nevermind, I found the answer I was looking for. I just add and it works like charm

                runOnUiThread(new Runnable() {
                              public void run() {
                               // Toast.makeText(activity, "Hello", Toast.LENGTH_SHORT).show();
                                Intent edit = new Intent(getParent(), MerchantActivity.class);
                                TabGroupActivity parentsActivity = (TabGroupActivity)getParent();
                                parentsActivity.startChildActivity("MerchantActivity", edit);
                              }
                            });

Upvotes: 0

Vit Khudenko
Vit Khudenko

Reputation: 28418

Try to run the parentsActivity.startChildActivity("MerchantActivity", edit); on the main UI thread. Something like this:

runOnUiThread(new Runnable() {
    public void run() {
        parentsActivity.startChildActivity("MerchantActivity", edit);
    }
});

BTW, you will have to declare TabGroupActivity parentsActivity and Intent edit as final for this.

Upvotes: 1

Related Questions