0

enter image description hereenter image description hereSo I'm working on an app where when the user clicks a title in a list picker, another screen opens and the picture of the place is shown. I've been looking around and I can't figure out how to send the data from one screen to another along with the data of a picture. I've seen the use of Tinydb, but I'm honestly very confused about it. I'm using MIT App Inventor 2 btw. I've included images to help with my confusion

BaconAF
  • 1
  • 1
  • You can send data by intent... Check this [link](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application)... – Shohan Ahmed Sijan Jan 10 '18 at 06:23

2 Answers2

0
  1. Using Static Variable :

    • If the title data is static then you can define it as static so that way it will be the same copy for all the objects of Screen1.
    • Now you can access it from Screen2 by saying Screen1.title
  2. Using intents to communincate

    • If the title is a data that can be passed via an intent that use to pass the title
    • For example if title is a string from Screen1 intent.putExtra("TITLE", title);
    • In Screen2 you can do the following

      String newString;
      if (savedInstanceState == null) {
           Bundle extras = getIntent().getExtras();
           if(extras == null) {
               newString= null;
           } 
           else {
                newString= extras.getString("TITLE");
           } 
      } 
      else {
                newString=(String)savedInstanceState.getSerializable("TITLE");
      }
      
  3. Using interfaces for callbacks:

    • If the title is really that important you can pass an interface to Screen2 and let Screen1 class implement this interface
    • Have a reference to Screen1 class interface
    • access the title by making a callback to this class of Screen1
  4. Having Direct reference to Screen1 class:

    • Let Screen2 have a direct reference to that particular object of Screen1 class that contains the title
    • That way Screen2 can access the attributes of Screen1 class
    • Remember when having a direct reference you want the same object of Screen1 to be passed you can do this by using this keyword
Jai
  • 3,211
  • 2
  • 17
  • 26
0

Passing Data Through Intent() is the Best way for passing data to another activity or fragment.and it is very easy to use. Refer This Link

Normal1One
  • 219
  • 3
  • 11
  • So I understand most of the actual code that is going on with the intent, but I'm utterly confused on how to put that into the block formation which is forced upon the user in App Inventor. If you could provide any other feedback, that would be great. – BaconAF Jan 11 '18 at 05:06