Sunday, July 11, 2010

[android-developers] Application throws exception when I rotate the device

I have developed simple application of progress bar in that when I hit
the button then it will do some work in background and one progress
bar is visible on foreground. afte completing back ground work it
display the same screen. It works fine if I don't rotate mobile but
when I rotate mobile then it throws
java.lang.IllegalArgumentException: View not attached to window
manager

I know when we rotate the device or open keypad it starts activity
restarted. But How to avoid this error.
My code is

public class TestProgressBar extends Activity implements
OnClickListener
{
/** Called when the activity is first created. */

Button hitMe;
boolean test;
Handler mHandler = new Handler();
ProgressDialog myProgressDialog = null;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println ("Before setContentView");
hitMe = (Button)findViewById(R.id.widget30);
System.out.println ("Before rsgistering with listener");

hitMe.setOnClickListener(this);
System.out.println ("after rsgistering with listener");

}


public void onClick(View v)
{
if (v==hitMe)
{
final ProgressDialog myProgressDialog ;
myProgressDialog = ProgressDialog.show(this, "Please wait...",
"Doing Extreme Calculations...", true);
new Thread()
{

public void run() {
try{
// Do some Fake-Work
for (int i=00;i<100000;i++)
{
System.out.println ("****************");
}
System.out.println ("Outside for loop");
} catch (Exception e) { }
// Dismiss the Dialog
//setContentView(R.layout.main1);
myProgressDialog.dismiss();


}

}.start();

}


}

}

Please help me. Thanks in advance

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate