Android从SplashActivity切换到AnotherActivity时变黑屏幕

问题描述:

SplashScreen活动移动到AnotherActivity时,我遇到问题。问题是在SplashScreen消失之后和MainActivity屏幕加载之前,我得到BlackScreenAndroid从SplashActivity切换到AnotherActivity时变黑屏幕

有没有人有任何建议?

这里我的代码:

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 }); 
    } 
+0

发布从启动屏幕开始的活动的'onCreate()' – 2013-05-13 09:47:03

+0

@DavidWasser使用其他活动的oncreate进行更新 – String 2013-05-13 09:53:17

+0

我没有看到任何明显的内容。您的活动布局可能需要很长时间才能完成?你看过logcat吗?有没有任何错误或其他信息?您是否曾尝试从启动画面中打开简单的活动(以查看问题是出现在启动画面还是启动的活动中)? – 2013-05-13 10:08:34

添加AnotherActivity到AndroidManifest.xml

AndroidManifest.xml

<activity 
    android : label ="@string/app_name" 
    android:name=".AnotherActivity" 
</activity> 
添加这两条线
+0

不清楚你想说什么? – String 2013-05-14 05:53:19

+0

加我facebook,fb.com/hansdinosourlove – rupinder 2013-05-14 08:43:54

+0

我会把你的照片发给你 – rupinder 2013-05-14 08:44:20