多项活动并将结果放在最后一项活动上

时间:2018-09-20 16:35:02

标签: android

在我的android应用程序中,如果使用意图,我想进行一些其他活动。

如果用户在活动A上选择正确答案,则会带到活动C

[Activity A]->[activity C]

否则,用户在活动A中选择了错误的答案,它将带用户进入活动B,然后再进入活动C

[Activity A]->[activity B]->[Activity C]

活动C用于显示结果。

但是,当我在活动C中编写代码以显示结果时。结果没有显示,使我再次回到活动A。

    TextView text = (TextView) findViewById(R.id.Solution);
    ImageView imagee = (ImageView) findViewById(R.id.solutionImage);
    String cconection = getIntent().getStringExtra("SpinConnection");//get from Activity B
    String ccondition = getIntent().getStringExtra("SpinCondition");//Get from Activity B
    String txtPowerSupply = getIntent().getStringExtra("PowerCable"); //get from Activity A

    if (txtPowerSupply.equals("PowerOff")) {

        text.setText("A+");
        imagee.setImageResource(R.drawable.sakura);
    }

    if (cconection.equals("Not properly connected") && ccondition.equals("Good")) {
    text.setText("B+");
    imagee.setImageResource(R.drawable.sakura); }

活动A

               switch(view.getId()) {
        case R.id.PowerOn:
            if (checked)
            {
                Intent monpage = new Intent(ActivityA.this, com.example.lenovo.computerhardwarediagnostic.ActivityB.class);
                startActivity(monpage);
            }
            break;
        case R.id.PowerOff:
            if (checked) {
                //Intent intent = new Intent(getApplicationContext(), Solution.class);
                //int genderID = powerSupply.getCheckedRadioButtonId();
                Intent data = new Intent(ActivityA.this, com.example.lenovo.computerhardwarediagnostic.ActivityC.class);
                data.putExtra("PowerCable","PowerOff");
                startActivity(data);
               finish();
            }
            break;
        }

活动B

            if(fact1.equalsIgnoreCase("Not properly connected")&&fact2.equalsIgnoreCase("Good"))
            {
                Intent intent = new Intent(ActivityB.this, ActivityC.class);
                intent.putExtra("SpinConnection","Not properly connected");
                intent.putExtra("SpinCondition","Good");
                startActivity(intent);

            }

我是Android的初学者。你能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

问题在于,您只能检索发起ActivityC的意图,因此存储在ActivityA发送的意图中的信息会丢失。

ActivityB中,从ActivityA中提取信息,并将其传递给ActivityC

尝试一下:


活动A

               switch(view.getId()) {
        case R.id.PowerOn:
            if (checked)
            {
                Intent monpage = new Intent(ActivityA.this, com.example.lenovo.computerhardwarediagnostic.ActivityB.class);

                //Pass the info to ActivityB
                monpage.putExtra("PowerCable","PowerOn");

                startActivity(monpage);
            }
            break;
        case R.id.PowerOff:
            if (checked) {
                //Intent intent = new Intent(getApplicationContext(), Solution.class);
                //int genderID = powerSupply.getCheckedRadioButtonId();
                Intent data = new Intent(ActivityA.this, com.example.lenovo.computerhardwarediagnostic.ActivityC.class);
                data.putExtra("PowerCable","PowerOff");
                startActivity(data);
               finish();
            }
            break;
        }

活动B

if(fact1.equalsIgnoreCase("Not properly connected")&&fact2.equalsIgnoreCase("Good"))
            {
                //getting info from ActivityA
                String powerCableValue = getIntent().getStringExtra("PowerCable");

                Intent intent = new Intent(ActivityB.this, ActivityC.class);
                //passing info to ActivityC
                intent.putExtra("PowerCable",powerCableValue);

                intent.putExtra("SpinConnection","Not properly connected");
                intent.putExtra("SpinCondition","Good");
                startActivity(intent);

            }