EditText.getText().toString() crashes

前端 未结 2 1289
不思量自难忘°
不思量自难忘° 2021-01-24 03:19

In my android application , I have 3 dialogue boxes in which the user puts info into 3 editTexts and it will display the one of the data onto another class/page after it randoml

相关标签:
2条回答
  • 2021-01-24 03:34

    I believe I see the problem. You are trying to access your Array but it is an instance variable instead of static so it is being killed off when you exit your Activity. You can either put them in a static class and access them that way or pass a String variable through your Intent, depending on what you need.

    If you have the value of the String you need when you leave MainActivity then I would probably just pass it through your Intent. If the value depended on something in one of your other Activities then I would consider putting it in a separate class but it doesn't look like that's what you need here

    Edit

    You are already doing it here, kind of

    Intent i  = new Intent(MainActivity.this, resultScreen.class);
         i.putExtra("display" , displayChoice);
    
         Intent intent = new Intent(MainActivity.this,loadingScreen.class);
    

    But you aren't starting the Activity that would get the String

    i.putExtra("display" , displayChoice);
    

    that line would pass a String with key "displpay" and value of displayChoice, although I think that value is an empty String at that point, but you don't start that Activity. I'm lost on how your flow is suppose to work but basically you would do something like this

    String displayChoice = "testValue";   // some arbitrary value--whatever you need to send
    Intent i  = new Intent(MainActivity.this, resultScreen.class);  // create the Intent
    i.putExtra("display" , displayChoice);  // add the extra
    startActivity(i);  //start the Activity
    

    then to get the value inside resultScreen in onCreate()

    Intent recIntent = getIntent();  // get the Intent that started this Activity
    String value = recIntent.getStringExtra("display");   // get the value using the key
    // value now equals "testValue"
    
    0 讨论(0)
  • 2021-01-24 03:39

    I think your app chash because you have an ANR: "Application Not Responding" because you are running a long procces inside the UIThread. (onCreate() method is form the UIThread)

    Use rather as an Asyntack for your sleeping thread or one handler (with messages).

    If you need more I can edit your code tomorrow.

    0 讨论(0)
提交回复
热议问题