0

SplashScreen活动转移到AnotherActivity. 问题是我在屏幕加载BlackScreen之前SplashScreen消失了。MainActivity

有没有人有什么建议?

这是我的代码:

public class Splash  extends Activity{

    public List<SaxMessage> torimsg = new ArrayList<SaxMessage>();
    static final int DIALOG_ERROR_CONNECTION = 1;
    static final int DIALOG_ERROR_CONNECTION2 = 2;
    static final int DIALOG_ERROR_CONNECTION3 = 3;
    Boolean connected;
    String dialogMessage;
    Context context;
     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SplashHandler mHandler = new SplashHandler();
        setContentView(R.layout.splash);
        context=getApplicationContext();
         connected=isOnline(getApplicationContext());
            Log.d("connection","connection:"+connected);
            // Create a Message object
            Message msg = new Message();
            //Assign a unique code to the message.
            //Later, this code will be used to identify the message in Handler class.
            msg.what = 0;
            // Send the message with a delay of 3 seconds(3000 = 3 sec).
            mHandler.sendMessageDelayed(msg, 1000);
        } //onCreate

      private Boolean isOnline(Context conn) {
            ConnectivityManager cm = (ConnectivityManager)conn. getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkinfo = cm.getActiveNetworkInfo();
            if (networkinfo != null && networkinfo.isAvailable()
                    && networkinfo.isConnected()) {     
                return true;
            }
            return false;
        }
        @Override
        protected Dialog onCreateDialog(int id) {
          Dialog dialog = null;

          switch (id) {
          case DIALOG_ERROR_CONNECTION:
            AlertDialog.Builder errorDialog = new AlertDialog.Builder(this);
            errorDialog.setTitle("Error");
            errorDialog.setMessage(dialogMessage);
            errorDialog.setNeutralButton("Retry",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int id) {
                  dialog.dismiss();
                  torimsg.clear();
                  new DownloadLocalXmlTask().execute();  
              }
            });

           AlertDialog errorAlert = errorDialog.create();
           return errorAlert;
         case DIALOG_ERROR_CONNECTION2:
                AlertDialog.Builder errorDialog1 = new AlertDialog.Builder(this);
                errorDialog1.setTitle("Error");
                errorDialog1.setMessage("No internet connection.");
                errorDialog1.setNeutralButton("OK",
                new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                   Splash.this.finish();
                  }
                });

               AlertDialog errorAlert1 = errorDialog1.create();
               return errorAlert1;

        case DIALOG_ERROR_CONNECTION3:
             AlertDialog.Builder errorDialog2 = new AlertDialog.Builder(this);
            errorDialog2.setTitle("Error");
            errorDialog2.setMessage(dialogMessage);
            errorDialog2.setNeutralButton("Ok",
            new DialogInterface.OnClickListener() {

              public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();         
               Splash.this.finish();
              }
            });

           AlertDialog errorAlert2 = errorDialog2.create();
           return errorAlert2;

          default:
            break;
          }
        return dialog;
        }


        private class DownloadXmlTask extends AsyncTask<String, Void, List<SaxMessage>>{
            @Override
            protected List<SaxMessage> doInBackground(String... urls) {

                try{
                        SAXParserFactory saxParserFactory= SAXParserFactory.newInstance();
                        SAXParser saxParser = saxParserFactory.newSAXParser();

                        XMLReader xr = saxParser.getXMLReader();
                        URL sourceUrl = new URL ("http://toucheradio.com/toneradio/android/toriLite/toriplaylist.xml");
                        RssHandler handler = new RssHandler();
                        xr.setContentHandler(handler);                  
                        xr.parse(new InputSource(sourceUrl.openStream()));          
                        torimsg= handler.getMessages();
                        torimsg.remove(0);
                        return torimsg;
                    } 
                    catch(UnknownHostException e)
                    {
                        showMyDialog(e.getMessage());
                        return null;
                    }
                    catch(SAXParseException se)
                    {
                        showMyDialog(se.getMessage());
                        return null;
                    }
                    catch (Exception e) {
                        showMyDialog(e.getMessage());
                        return null;
                    }   
            }

            @Override
            protected void onPostExecute(List<SaxMessage> result) {  
                if(result==null)
                {               
                    showDialog(DIALOG_ERROR_CONNECTION);
                }
                else
                {
                    Intent intent= new Intent(Splash.this,TORiLTActivity.class);
                    Bundle b=new Bundle();
                    b.putParcelableArrayList("torimsg", (ArrayList<? extends Parcelable>) torimsg); 
                    intent.putExtras(b);             
                    startActivity(intent); 
                    // finish the current activity
                    Splash.this.finish();
                }
            }
        }

        private void showMyDialog(String b) {
            Splash.this.dialogMessage=b;
        }
     private class SplashHandler extends Handler {

            //This method is used to handle received messages
            public void handleMessage(Message msg)
              {
                // switch to identify the message by its code
                switch (msg.what)
                {
                default:
                case 0:
                  super.handleMessage(msg);
                  if(connected==false)
                    {                   
                        showDialog(DIALOG_ERROR_CONNECTION2);   
                    }
                    else
                    {
                        new DownloadXmlTask().execute();
                    }
                }
              } 
    }
}

更新:

public void onCreate(Bundle savedInstanceState) {
        Log.i("HS1", "onCreate");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Bundle recdData = getIntent().getExtras();

        messages = recdData.getParcelableArrayList("torimsg");
        //new getHtmlDataAync().execute();
        albumAdapter=new LazyAdapter(TORiLTActivity.this, messages);  
        this.setListAdapter(albumAdapter);
        bindToService();
        //contentList.setFastScrollEnabled(true);

        buttonMethode();
        AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 1);

           AdWhirlTargeting.setAge(23);

           AdWhirlTargeting.setGender(AdWhirlTargeting.Gender.MALE);

           AdWhirlTargeting.setKeywords("online games gaming");

           AdWhirlTargeting.setPostalCode("94123");

           AdWhirlTargeting.setTestMode(false);

           AdWhirlLayout adWhirlLayout = new AdWhirlLayout(this,"ce9849662b9844468e942e4e3de6e2c8");

           RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);


           layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

           layout = (LinearLayout)findViewById(R.id.linearlayout01);

           layout.setGravity(Gravity.CENTER_HORIZONTAL);

           layout.addView(adWhirlLayout, layoutParams);

           layout.invalidate();    

        this.facebookConnector = new FacebookConnector(FACEBOOK_APPID, this,
                getApplicationContext(), new String[] { FACEBOOK_PERMISSION }); 
    }
4

1 回答 1

-1

将 AnotherActivity 添加到您的 AndroidManifest.xml

将这两行添加到AndroidManifest.xml

<activity
    android : label ="@string/app_name"
    android:name=".AnotherActivity"
</activity>
于 2013-05-13T14:18:23.967 回答