0

We are trying to take in a room number (e.g. C123) from a user in one activity and use that variable in a different activity. The other activity would look like:

roomNewNums.put("A100", "1")

...

roomNewNums.put("C303", "198")

We were using this to send over the variable from the second activity (first activity is irrelevant):

public static Bundle myNums = new Bundle();

SecondActivity.myNums.putString("newNumber", "destPos");

We used this to receive it in the third activity:

String newNum = SecondActivity.myNum.getString("newNumber");

What we think is the main error is the putString. It keeps saying

Cannot resolve symbol 'putString'

We checked multiply websites and forums online and all were no help.

Any help is much appreciated.

Pang
  • 9,564
  • 146
  • 81
  • 122
J. Finlay
  • 83
  • 7

2 Answers2

0
  1. Create a new class MyApplication extending android.app.Application
  2. Create a static Bundle object in MyApplication class.

    public static Bundle mBundle = new Bundle():
    
  3. Add data to Bundle using key-value pair from SecondActivity:

    MyApplication.mBundle.putString("newNumber", "destPos");
    
  4. In ThirdActivity, Get data from Bundle:

    String newNum = MyApplication.mBundle.getString("newNumber");
    
  5. Specify the android:name property in the <application> node in AndroidManifest.xml:

    <application 
        android:name=".MyApplication"
        android:icon="@drawable/icon" 
        android:label="@string/app_name">
    
        ................
        ....................
    </application> 
    

Hope this will help~

Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
0

There are 2 ways I can think of doing this

1) Use shared preference to store room number in first activity and later fetch it from shared preference and use it .

2) Use singleton pattern to store data in model class and use it anymwhere in your app

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154