开发者

Android Application that makes HTTP calls in multiple Activities does not return data correctly

开发者 https://www.devze.com 2023-02-28 23:18 出处:网络
The app makes calls (utilizing HttpPost) to a PHP files that sends a queries to a MySQL database. The PHP file parses the data into a Java-friendly string statement that can easily be converted to a S

The app makes calls (utilizing HttpPost) to a PHP files that sends a queries to a MySQL database. The PHP file parses the data into a Java-friendly string statement that can easily be converted to a String[] array (String[] str = data_from_php.split(",");); so the data id formatted like so: "Item 1,Item 2,Item 3".

Multiple Activities run that type of code back-to-back:

(1) Activity 1 will use the String[] array to build a ListActivity, which is working fine. When the user clicks a list item, it pulls the Text from that Object and forwards it to the next Activity (using putExtra).

(2) Activity 2 uses the extra data from A1 in the HttpPost method to get another String[] array to build another ListActivity. Again, the user chooses an item and extra data gets sent to Act 3.

(3) The 3rd Activity in the chain sends the data in the same manner as above, but this Activity display a chunk of da开发者_运维知识库ta in a TextView.

The issue is that from both Activities that have a List Array, if I choose the LAST item on any list (either Act 1, or 2), the next resulting Activity will return no data.

Has anyone encountered an issue like this? I feel as if I am overlooking something.


Maybe there are blank characters at the end of the PHP output, like Spaces or Newlines, that prevent the last item from beeing fetched properly in the next Activity. In PHP, a newline is made very easily by code like:

<?php
    echo 'test1,test2,test3';
?>
[whitespace here]

if the last ?> is not the true end of the PHP file but whitespaces are there like a simple newline at the end of the file, they are outputted and thus fetched by the HttpPost method. The file must begin with <? and end immediately after ?> on the same line to prevent this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号