Changed my codes and now no out of memory error
public class GalleryFragment extends Fragment {
ProgressBar progressBar;
TextView progressText;
JSONParser jsonParser = new JSONParser();
private static String url_download_photo_id = Global.url+"/clubs/download_photo_id.php";
private static String url_download_photo = Global.url+"/clubs/download_photo.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_CLUBS = "clubs";
private static final String TAG_PHOTO = "photo";
private static final String TAG_PHOTO_ID = "photo_id";
JSONArray clubs = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_gallery, container, false);
progressText = (TextView) rootView.findViewById(R.id.textView1);
progressBar = (ProgressBar) rootView.findViewById( R.id.progressBar1);
new DownloadPhotoId().execute();
return rootView;
}
class DownloadPhotoId extends AsyncTask<string,> {
protected String doInBackground(String... args) {
Log.v("DownloadPhotoId","doInBackground");
try {
List<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("club_id", ClubActivity.club_id));
JSONObject json = jsonParser.makeHttpRequest(url_download_photo_id,"GET", params);
Log.d("Download Image Id", json.toString());
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
getActivity().runOnUiThread(new Runnable() {
public void run() {
progressBar.setVisibility(View.VISIBLE);
}
});
clubs = json.getJSONArray(TAG_CLUBS);
progressBar.setMax(clubs.length());
for (int i = 0; i < clubs.length(); i++) {
JSONObject c = clubs.getJSONObject(i);
String photo_id = c.getString(TAG_PHOTO_ID);
progressBar.setProgress(i+1);
Log.v("Photo id"+i,""+photo_id);
new DownloadPhoto(photo_id).execute();
}
getActivity().runOnUiThread(new Runnable() {
public void run() {
progressBar.setVisibility(View.INVISIBLE);
}
});
}
else
{
}
} catch (JSONException e) {
problem();
e.printStackTrace();
}
catch(Exception e)
{
problem();
Log.v("Exception",""+e);
}
return null;
}
protected void onPostExecute(String file_url) {
}
}
class DownloadPhoto extends AsyncTask<string,> {
String photo_id = null;
DownloadPhoto(String pId)
{
photo_id = pId;
}
protected String doInBackground(String... args) {
Log.v("DownloadPhoto","doInBackground");
try {
List<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("photo_id", photo_id));
JSONObject json = jsonParser.makeHttpRequest(url_download_photo,"GET", params);
Log.d("Download Image Id", json.toString());
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
clubs = json.getJSONArray(TAG_CLUBS);
JSONObject c = clubs.getJSONObject(0);
String photo = c.getString(TAG_PHOTO);
Log.v("Photo id "+photo_id,""+photo);
}
else
{
}
} catch (JSONException e) {
problem();
e.printStackTrace();
}
catch(Exception e)
{
problem();
Log.v("Exception",""+e);
}
return null;
}
protected void onPostExecute(String file_url) {
}
}
void problem()
{
getActivity().runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getActivity(), "Something went wrong! Try again!",Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.INVISIBLE);
progressText.setVisibility(View.INVISIBLE);
}
});
}
}
download_photo_id.php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
if (isset($_GET["club_id"])) {
$club_id = $_GET['club_id'];
$result = mysql_query("SELECT photo_id FROM gallery WHERE club_id = '$club_id'") or die(mysql_error());
if (!empty($result)) {
if (mysql_num_rows($result) > 0) {
$response["clubs"] = array();
while ($row = mysql_fetch_array($result)) {
$clubs = array();
$clubs["photo_id"] = $row["photo_id"];
array_push($response["clubs"], $clubs);
}
$response["success"] = 1;
echo json_encode($response);
}
else {
$response["success"] = 0;
$response["message"] = "Not found";
echo json_encode($response);
}
}
else {
$response["success"] = 0;
$response["message"] = "Not found";
echo json_encode($response);
}
}
else {
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
echo json_encode($response);
}
?>
download_photo.php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
if (isset($_GET["photo_id"])) {
$photo_id = $_GET['photo_id'];
$result = mysql_query("SELECT photo FROM gallery WHERE photo_id = '$photo_id'") or die(mysql_error());
if (!empty($result)) {
if (mysql_num_rows($result) > 0) {
$response["clubs"] = array();
while ($row = mysql_fetch_array($result)) {
$clubs = array();
$clubs["photo"] = $row["photo"];
array_push($response["clubs"], $clubs);
}
$response["success"] = 1;
echo json_encode($response);
}
else {
$response["success"] = 0;
$response["message"] = "Not found";
echo json_encode($response);
}
}
else {
$response["success"] = 0;
$response["message"] = "Not found";
echo json_encode($response);
}
}
else {
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
echo json_encode($response);
}
?>