我有 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);
}