如何使用包

时间:2017-03-24 11:42:44

标签: android android-intent bundle

在我的代码中,我正在从两个来源恢复(邀请)Activity,具体取决于我想要将变量RemoteConnectionStepCounter设置为不同的值。为此,我使用不同的键和布尔值。

RemoteConnection.class代码:

package com.stipe.isemergencyrecoveryprocedures;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.stipe.isemergencyrecoveryprocedures.Auxilaries.Actions_done;

import java.lang.annotation.IncompleteAnnotationException;

/**
* Created by estikot on 6.3.2017..
*/

public class RemoteConnection extends AppCompatActivity {

int RemoteConnectionStepCounter = 1;
Button RemoteConnectionButtonYES;
Button RemoteConnectionButtonNO;
Button RemoteConnectionButtonContinue;
TextView RemoteConnectionHeader;
TextView RemoteConnectionStatement;
public static boolean BrowserChecksDone = false;
public static boolean RemoteConnectionYesStep2 = false;
public static boolean RemoteConnectionYesStep3 = false;
boolean IncreaseCounterBy1 = false;
boolean GoToStep5 = false;
//If another management terminal is used, this will be set to true (onNo case 9).
// We are using this in onNo case 8, if this is set to True go to LocalConnection directly



@Override
protected void onCreate(Bundle savedInstances){
    super.onCreate(savedInstances);
    setContentView(R.layout.remote_connection);
    this.RemoteConnectionButtonContinue = (Button) findViewById(R.id.RemoteConnectionButtonCONTINUE);
    this.RemoteConnectionButtonNO = (Button) findViewById(R.id.RemoteConnectionButtonNO);
    this.RemoteConnectionButtonYES = (Button) findViewById(R.id.RemoteConnectionButtonYES);
    this.RemoteConnectionStatement = (TextView) findViewById(R.id.RemoteConnectionStatement);
    this.RemoteConnectionHeader= (TextView) findViewById(R.id.RemoteConnectionHeader);
    this.showText();
}

@Override
protected void onResume(){
    super.onResume();
    //If we are cumming back from Browser Checks we need to increase counter by 1 and show text
    Bundle bundle = getIntent().getExtras();
    if(bundle != null) {
        IncreaseCounterBy1 = bundle.getBoolean("BCIncrease");
        GoToStep5 = bundle.getBoolean("ChangeStep");
    }
    if (IncreaseCounterBy1){
        RemoteConnectionStepCounter++;
        IncreaseCounterBy1 = false;
    }

    //If we are cumming back from NetworkChecks step8, and we currently see Welcome page, go directly to step 5(Log in to GUI)
    if (GoToStep5){
        RemoteConnectionStepCounter = 5;
        GoToStep5 = false;
    }

    this.showText();
}

@Override
public void onBackPressed(){
    //If there was a jump from step 2 to step 5 onYes, return it from 5 to 2
    if ((RemoteConnectionStepCounter == 5) || (RemoteConnectionYesStep2)){
        this.RemoteConnectionStepCounter = this.RemoteConnectionStepCounter - 3;
        RemoteConnectionYesStep2 = false;
    }
    //If there was a jump from step 3 to step 5 onYes, return it from 5 to 3
    if ((RemoteConnectionStepCounter == 5) || (RemoteConnectionYesStep3)){
        this.RemoteConnectionStepCounter = this.RemoteConnectionStepCounter - 2;
        RemoteConnectionYesStep3 = false;
    }
    else this.RemoteConnectionStepCounter --;

    if(this.RemoteConnectionStepCounter == 0){
        finish();
    }
    this.showText();
}


public void RemoteConnectionOnContinue(View View) {
    switch (this.RemoteConnectionStepCounter) {
        case 1: {
            this.RemoteConnectionStepCounter++;
            this.showText();
            break;
        }
        case 7: {
            //If browser checks are done, go to next step (Try logging in again)
            if(BrowserChecksDone){
                this.RemoteConnectionStepCounter++;
                showText();
            }
            //Go to Browser checks and state that checks are done
            else {
                Intent intent = new Intent(this, BrowserChecks.class);
                startActivity(intent);
            }
            break;
        }
    }
}

public void RemoteConnectionOnNo(View VIew){
    switch (this.RemoteConnectionStepCounter){
        case 2:{
            Intent intent = new Intent(this, BrowserChecks.class);
            startActivity(intent);
            break;
        }
        case 3:{
            RemoteConnectionStepCounter++;
            this.showText();
            break;
        }
        case 4:{
            //Go to NetworkChecks (Chapter 6)
            break;
        }
        case 5:{
            //Forgotten password, go to chapter 11.4, retrieve password and return here.
            break;
        }
        case 6:{
            this.RemoteConnectionStepCounter++;
            this.showText();
            break;
        }
        case 8:{
            //If we already tried with second management termianl go directly to Local Connection
            if(Actions_done.RemoteConnectionDiffMenTerm){
                Intent intent = new Intent(this, LocalConnection.class);
                startActivity(intent);
            }
            this.RemoteConnectionStepCounter++;
            this.showText();
            break;
        }
        case 9:{
            //Different management terminal will be used. Return to Management Terminal Setup (change WhereTo parameter)
            TerminalSetup.TerminalSetup_WhereTo = "RemoteConnection";
            RemoteConnectionStepCounter = 1;
            RemoteConnectionYesStep2 = false;
            RemoteConnectionYesStep3 = false;
            Actions_done.BrowserChecksDone = false;
            Actions_done.RemoteConnectionDiffMenTerm = true;
            Intent intent = new Intent(this, TerminalSetup.class);
            startActivity(intent);
            break;
        }
    }
}

public void RemoteConnectionOnYes(View View) {
    switch (this.RemoteConnectionStepCounter) {
        case 2:{
            //Go to step 5
            this.RemoteConnectionStepCounter = this.RemoteConnectionStepCounter + 3;
            RemoteConnectionYesStep2 = true;   //Declare there was a jump from step2 to step5
            this.showText();
            break;
        }

        case 3:{
            //Go to step 5
            this.RemoteConnectionStepCounter = this.RemoteConnectionStepCounter + 2;
            RemoteConnectionYesStep3 = true;   //Declare there was a jump from step3 to step5
            this.showText();
            break;
        }
        case 4:{
            //Go to LocalConnection
        }
        case 5:{
            //Login to GUI
            this.RemoteConnectionStepCounter++;
            this.showText();
        }
        case 6:{
            //Go to chapter 8 SystemChecks and Recovery

        }
        case 8:{
            //Got to chapter 8 SystemChecks and Recovery
        }
        case 9:{
            //LocalConnection button is pressed go to Local Connection
        }
    }
}



//All text used
public void showText(){
    switch (this.RemoteConnectionStepCounter){
        case 1:{
            this.RemoteConnectionHeader.setText(R.string.RemoteConnectionHeader);
            this.RemoteConnectionStatement.setText(Html.fromHtml(getString(R.string.RemoteConnectionAccessISMURL)));
            this.showOk();
            break;
        }

        case 2:{
            this.RemoteConnectionStatement.setText(R.string.RemoteConnectionIsWelcomePageDisplayed);
            this.showYESNO();
            break;
        }

        case 3:{
            this.RemoteConnectionStatement.setText(R.string.RemoteConnectionIsWelcomePageDisplayed);
            this.showYESNO();
            break;
        }

        case 4:{
            this.RemoteConnectionStatement.setText(R.string.RemoteConnectionIfLocal);
            this.showYESNO();
            break;
        }

        case 5:{
            this.RemoteConnectionStatement.setText(R.string.RemoteConnectionClickLogIn);
            this.showForgottenPass_Ok();
            break;
        }

        case 6:{
            this.RemoteConnectionStatement.setText(R.string.RemoteConnectionAbleToLogIn);
            this.showYESNO();
            break;
        }

        case 7:{
            this.RemoteConnectionStatement.setText(R.string.RemoteConnectionRestartBrowser);
            this.showOk();
            break;
        }

        case 8:{
            this.RemoteConnectionStatement.setText(R.string.RemoteConnectionAbleToLogIn);
            this.showYESNO();
            break;
        }

        case 9:{
            this.RemoteConnectionStatement.setText(R.string.RemoteConnectionSecondMngTerminal);
            this.showDiffMngLocalConnect();
            break;
        }
    }
}   

//Show only YES and NO Buttons
public void showYESNO(){
    this.RemoteConnectionButtonYES.setVisibility(View.VISIBLE);
    this.RemoteConnectionButtonYES.setText(R.string.YES_Button);
    this.RemoteConnectionButtonNO.setVisibility(View.VISIBLE);
    this.RemoteConnectionButtonNO.setText(R.string.NO_Button);
    this.RemoteConnectionButtonContinue.setVisibility(View.GONE);
}

public void showForgottenPass_Ok(){
    this.RemoteConnectionButtonYES.setVisibility(View.VISIBLE);
    this.RemoteConnectionButtonYES.setText(R.string.OK_Button);
    this.RemoteConnectionButtonNO.setVisibility(View.VISIBLE);
    this.RemoteConnectionButtonNO.setText(R.string.ForgottenPassButton);
    this.RemoteConnectionButtonContinue.setVisibility(View.GONE);
}

public void showDiffMngLocalConnect(){
    this.RemoteConnectionButtonYES.setVisibility(View.VISIBLE);
    this.RemoteConnectionButtonYES.setText(R.string.ChooseConnectionLocalButton);
    this.RemoteConnectionButtonNO.setVisibility(View.VISIBLE);
    this.RemoteConnectionButtonNO.setText(R.string.DiffMngTerm);
    this.RemoteConnectionButtonContinue.setVisibility(View.GONE);
}

//Show only Continue Button, but set text to "OK"
public void showOk(){
    this.RemoteConnectionButtonYES.setVisibility(View.GONE);
    this.RemoteConnectionButtonNO.setVisibility(View.GONE);
    this.RemoteConnectionButtonContinue.setVisibility(View.VISIBLE);
    this.RemoteConnectionButtonContinue.setText(R.string.OK_Button);
}
}

使用此代码邀请班级:

1)BrowserChecks

switch (this.BCWhereTo.toString()) {

            //If BC is called from Local connection, return to local connection, and state that BC is done
            case "LocalConnection":{
                Actions_done.BrowserChecksDone = true;
                boolean BCIncreaseCounterBy1 = true;
                Intent intent = new Intent(this, LocalConnection.class);
                intent.putExtra("Increase", BCIncreaseCounterBy1);
                startActivity(intent);
                break;
            }

            //If BC is called from Remote connection, return to remote connection, and state that BC is done
            case "RemoteConnection":{
                Actions_done.BrowserChecksDone = true;
                boolean BCIncreaseCounterBy1 = true;
                Intent intent = new Intent(this, RemoteConnection.class);
                intent.putExtra("BCIncrease", BCIncreaseCounterBy1);
                startActivity(intent);
                break;
            }
        }

2)NetworkChecks

case 8:{
            boolean GoToStep5 = true;
            Intent intent = new Intent(this, RemoteConnection.class);
            intent.putExtra("ChangeStep", GoToStep5);
            startActivity(intent);
            break;
        }

如果我在“RemoteConnection”中只使用一个布尔值,它可以正常工作,如果我尝试使用完整代码,我的应用程序崩溃并收到以下内容:

  

E / AndroidRuntime:致命异常:主要                     java.lang.IllegalStateException:无法执行android:onClick的方法                         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)                         在android.view.View.performClick(View.java:4204)                         在android.view.View $ PerformClick.run(View.java:17355)                         在android.os.Handler.handleCallback(Handler.java:725)                         在android.os.Handler.dispatchMessage(Handler.java:92)                         在android.os.Looper.loop(Looper.java:137)                         在android.app.ActivityThread.main(ActivityThread.java:5041)                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:511)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)                         at dalvik.system.NativeStart.main(Native Method)                      引起:java.lang.reflect.InvocationTargetException                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:511)                         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)                         在android.view.View.performClick(View.java:4204)                         在android.view.View $ PerformClick.run(View.java:17355)                         在android.os.Handler.handleCallback(Handler.java:725)                         在android.os.Handler.dispatchMessage(Handler.java:92)                         在android.os.Looper.loop(Looper.java:137)                         在android.app.ActivityThread.main(ActivityThread.java:5041)                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:511)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)                         at dalvik.system.NativeStart.main(Native Method)                      引起:java.lang.NullPointerException                         在com.ericsson.isemergencyrecoveryprocedures.BrowserChecks.BrowserChecksOnContinue(BrowserChecks.java:116)                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:511)                         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)                         在android.view.View.performClick(View.java:4204)                         在android.view.View $ PerformClick.run(View.java:17355)                         在android.os.Handler.handleCallback(Handler.java:725)                         在android.os.Handler.dispatchMessage(Handler.java:92)                         在android.os.Looper.loop(Looper.java:137)                         在android.app.ActivityThread.main(ActivityThread.java:5041)                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:511)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)                         at dalvik.system.NativeStart.main(Native Method)   申请已终止。

如果有人可以为此问题提出解决方案。 先感谢您 :-) 菌柄

0 个答案:

没有答案