2013-09-27 55 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

相关问题