2013-09-27 50 views
0

我有3個活動做某種網絡訪問,並獲得與3個相應的XML佈局(我將它稱爲A,B,C)的響應。 A通過Intent將數據傳遞給B,B通過Intent將數據傳遞給C.當我執行應用程序時,只有第三個活動/屏幕出現在模擬器上。只有最後一個活動得到顯示

我該如何保留序列,比如A先得到顯示,然後我點擊一個按鈕然後去B,然後點擊一個按鈕,然後轉到C.(我是否必須使用活動生命週期,因爲每個活動都獲得響應。經過網絡接入)

代碼(相關部分)是:

A- 
     username = (EditText) findViewById(R.id.editTextusername); 
     password = (EditText) findViewById(R.id.editTextpassword); 

     submit = (Button)findViewById(R.id.submit); 
     //sampletext = (TextView) findViewById(R.id.textView1); 

     submit.setOnClickListener(new View.OnClickListener() { 

    @Override 
    public void onClick(View v) { 

     if(username.getText().length()>0 && password.getText().length()>0) 
     { 
      URLconnector ss = new URLconnector(); 
      ss.execute("SOME URL"); 

     //network access in an async task, get response, 
     } 

Intent part of activity A - on post execute method of async task 

if(result != null) 
      { 
      Intent intentA = new Intent(mContext, B); 
      Bundle bundle = new Bundle(); 
      bundle.putString("responsedata",result.substring); 

      tokenIntent.putExtras(bundle); 
      startActivity(intentA); 


B- 

URLconnector ss = new URLconnector(); 
      ss.execute("SOME URL"); 

     //network access in an async task, get response, 
     } 

Intent part of activity B - on post execute method of async task 

if(result != null) 
      { 
      Intent intentB = new Intent(mContext, c); 



      startActivity(tokenIntent); 



c- 

URLconnector ss = new URLconnector(); 
      ss.execute("SOME URL"); 

     //network access in an async task, get response, 
     } 

Intent part of activity c- on post execute method of async task 

if(result != null) 
      { 




       text3.setText(result); 

} 
+1

你可以請張貼你的代碼嗎?一旦你發佈它,幫助你將會容易得多。 – MrByte

+0

@DemVoids當然,我已經發布了相關部分。請立即檢查。 – androidnoob

回答

0

如果預期的效果是有下一個觸發,並且希望他們之間的暫停中,那麼你需要有某些來自用戶的阻止請求阻止它進入下一個屏幕。

如果你讓他們只是互相打電話,那麼他們會比任何你設置顯示的視覺提示都要快。根據您想要做的事情,放置警報消息或按照您提到的向前推進提供按鈕。聽起來好像您的建築設計會更好地在一個屏幕上顯示您想要的所有內容,而不是在單個活動中使用多個屏幕。而不是通過所有三個進展。也許有2個AsyncTasks爲你工作。

+0

感謝您的輸入,網絡響應非常龐大,無法放入單個屏幕(至少在我的模擬器上)。 – androidnoob

+0

如果您只是顯示不適合單個屏幕的回覆,但只顯示大量數據,那麼使信息滾動應該可以。 –

+0

啊,讓視圖成爲滾動視圖?說得通。乾杯! – androidnoob

相關問題