0

I am new in android studio Currently I am working with android project where dynamic image is loading from remote server. I done it with static array. but I want to get these array from remote page. here is the static array

String[] itemTitle =
            {
            "1st Title",
            "2nd Title",
            "3rd Title",
            "4th Title"
            };

    String[] itemDate =
            {
                    "11 Sept 17",
                    "21 Sept 17",
                    "12 Sept 17",
                    "21 Sept 17"
            };
    String[] thumb =
            {
                    "1st Thumb",
                    "2nd Thumb",
                    "3rd Thumb",
                    "4th Thumb"
            };

Now I want to load these array from remote server http://www.example.com/getArray.php I already made the php file. but how to get the array from the remote url from android studio?

But I can't understand what to do?

  • Try using json_encode() in PHP to echo the array. Then decode JSON on your andorid code. – S.Gartmeier Sep 26 '17 at 10:19
  • In my openion you should create a REST api and send these data in JSON format so that your android app can parse the data. – Biswajit Sep 26 '17 at 10:20
  • @natheriel its not duplicate as you said. your suggested article is about PHP. But i want to get it in android studio – SANJOY DASGUPTA Sep 26 '17 at 10:23
  • well, in this case have a look at: https://stackoverflow.com/questions/9605913/how-to-parse-json-in-android. If you return JSON at your getArray.php location, then you could use the answer and info from that question to read your JSON for future use. – S.Gartmeier Sep 26 '17 at 10:30

1 Answers1

1

Check this tutorial this explain how can you create REST api in PHP How to create REST API in PHP

After creating you can parse these arrays one by one in your android project.

Omar Hayat
  • 378
  • 2
  • 12
  • I said i already created the php page with array but I want to get the array from the PHP file to android studio – SANJOY DASGUPTA Sep 26 '17 at 10:57
  • You have to create REST api first and then you can call that api using volley and then you can parse that array in your android project. – Omar Hayat Sep 26 '17 at 11:00
  • Means you have encode your array in json and after that you can use it in android project – Omar Hayat Sep 26 '17 at 11:01
  • If you done that use https://www.itsalif.info/content/android-volley-tutorial-http-get-post-put Volley to get your array from server and parse it. – Omar Hayat Sep 26 '17 at 11:03