I've tried different things, but I still keep the same error:

android.view.WindowManager$BadTokenException: Unable to add window  At
this line:

alertDialog.show();

Can you look at the code?

public class Main extends Activity implements Runnable {

        private static final int STOPSPLASH = 0;
        private ArrayList<RssItem> rssItems = new ArrayList<RssItem>();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.splashscreen);

        LoadData();
    }

    public void LoadData()
    {
          Thread t1 = new Thread(this);
         t1.start();
    }

        private Handler handler = new Handler()
        {
        @Override
                public void handleMessage(Message msg)
                {
                if(!rssItems.isEmpty())
                {
                                switch (msg.what) {
                                case STOPSPLASH:
                                        //remove SplashScreen from view
                                        //splash.setVisibility(View.GONE);
                                        Intent intent = new Intent(
                                        "news.displayNews");
                                        
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                        NewsDisplayer.rssItems.clear();
                                        NewsDisplayer.rssItems.addAll(rssItems);

                                        startActivity(intent);
                                        Close();
                                        break;
                                }
                }
                else
                {
                        if (!isFinishing())
                        {
                        AlertDialog.Builder builder = new
AlertDialog.Builder(Main.this);
                        builder.setMessage("No connection.")
                                   .setTitle("error...")
                               .setCancelable(false)
                               .setPositiveButton("Again", new
DialogInterface.OnClickListener() {
                                   public void onClick(DialogInterface dialog, 
int id)
{
                                        dialog.dismiss();
                                                LoadData();
                                   }
                               })
                               .setNegativeButton("Close", new
DialogInterface.OnClickListener() {
                                   public void onClick(DialogInterface dialog, 
int id)
{
                                                dialog.dismiss();
                                                System.exit(0);;
                                   }
                               });

                        AlertDialog alert = builder.create();
                        alert.show();
                        }
                }
            }
         };

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to