Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.toloee.iman.haminjuri;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import org.apache.http.NameValuePair;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.app.ListActivity;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v7.app.ActionBarActivity;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemClickListener;
- import android.widget.ArrayAdapter;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
- import android.widget.TextView;
- public class MainActivity extends ActionBarActivity {
- private ListView mListView;
- private ProgressDialog pDialog;
- JSONParser jParser = new JSONParser();
- ArrayList<HashMap<String, String>> productsList;
- private static String url_all_products = "http://api.androidhive.info/android_connect/get_all_products.php";
- private static final String TAG_SUCCESS = "success";
- private static final String TAG_PRODUCTS = "products";
- private static final String TAG_PID = "id";
- private static final String TAG_NAME = "name";
- JSONArray products = null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // Hashmap for ListView
- productsList = new ArrayList<HashMap<String, String>>();
- // Loading products in Background Thread
- // new LoadAllProducts().execute();
- }
- // Response from Edit Product Activity
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- // if result code 100
- if (resultCode == 100) {
- // if result code 100 is received
- // means user edited/deleted product
- // reload this screen again
- Intent intent = getIntent();
- finish();
- startActivity(intent);
- }
- }
- class LoadAllProducts extends AsyncTask<String, String, String> {
- /**
- * Before starting background thread Show Progress Dialog
- * */
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- pDialog = new ProgressDialog(MainActivity.this);
- pDialog.setMessage("Loading products. Please wait...");
- pDialog.setIndeterminate(false);
- pDialog.setCancelable(false);
- pDialog.show();
- }
- /**
- * getting All products from url
- * */
- protected String doInBackground(String... args) {
- // Building Parameters
- List<NameValuePair> params = new ArrayList<NameValuePair>();
- // getting JSON string from URL
- JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
- // Check your log cat for JSON reponse
- Log.d("All Products: ", json.toString());
- try {
- // Checking for SUCCESS TAG
- int success = json.getInt(TAG_SUCCESS);
- if (success == 1) {
- // products found
- // Getting Array of Products
- products = json.getJSONArray(TAG_PRODUCTS);
- // looping through All Products
- for (int i = 0; i < products.length(); i++) {
- JSONObject c = products.getJSONObject(i);
- // Storing each json item in variable
- String id = c.getString(TAG_PID);
- String name = c.getString(TAG_NAME);
- // creating new HashMap
- HashMap<String, String> map = new HashMap<String, String>();
- // adding each child node to HashMap key => value
- map.put(TAG_PID, id);
- map.put(TAG_NAME, name);
- // adding HashList to ArrayList
- productsList.add(map);
- }
- } else {
- // no products found
- // Launch Add New product Activity
- Intent i = new Intent(getApplicationContext(),
- MainActivity.class);
- // Closing all previous activities
- i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(i);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * After completing background task Dismiss the progress dialog
- * **/
- protected void onPostExecute(String file_url) {
- // dismiss the dialog after getting all products
- pDialog.dismiss();
- // updating UI from Background Thread
- runOnUiThread(new Runnable() {
- public void run() {
- /**
- * Updating parsed JSON data into ListView
- * */
- mListView = (ListView) findViewById(R.id.listView1);
- ListAdapter adapter = new SimpleAdapter(MainActivity.this, productsList, R.layout.pat,
- new String[] { "name" },new int[]{R.id.textView1});
- mListView.setAdapter(adapter);
- }
- });
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- package com.toloee.iman.haminjuri;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.UnsupportedEncodingException;
- import java.util.List;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.client.utils.URLEncodedUtils;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.util.Log;
- public class JSONParser {
- static InputStream is = null;
- static JSONObject jObj = null;
- static String json = "";
- // constructor
- public JSONParser() {
- }
- // function get json from url
- // by making HTTP POST or GET mehtod
- public JSONObject makeHttpRequest(String url, String method,
- List<NameValuePair> params) {
- // Making HTTP request
- try {
- // check for request method
- if(method == "POST"){
- // request method is POST
- // defaultHttpClient
- DefaultHttpClient httpClient = new DefaultHttpClient();
- HttpPost httpPost = new HttpPost(url);
- httpPost.setEntity(new UrlEncodedFormEntity(params));
- HttpResponse httpResponse = httpClient.execute(httpPost);
- HttpEntity httpEntity = httpResponse.getEntity();
- is = httpEntity.getContent();
- }else if(method == "GET"){
- // request method is GET
- DefaultHttpClient httpClient = new DefaultHttpClient();
- String paramString = URLEncodedUtils.format(params, "utf-8");
- url += "?" + paramString;
- HttpGet httpGet = new HttpGet(url);
- HttpResponse httpResponse = httpClient.execute(httpGet);
- HttpEntity httpEntity = httpResponse.getEntity();
- is = httpEntity.getContent();
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(
- is, "iso-8859-1"), 8);
- StringBuilder sb = new StringBuilder();
- String line = null;
- while ((line = reader.readLine()) != null) {
- sb.append(line + "n");
- }
- is.close();
- json = sb.toString();
- } catch (Exception e) {
- Log.e("Buffer Error", "Error converting result " + e.toString());
- }
- // try parse the string to a JSON object
- try {
- jObj = new JSONObject(json);
- } catch (JSONException e) {
- Log.e("JSON Parser", "Error parsing data " + e.toString());
- }
- // return JSON String
- return jObj;
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="50dp">
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="70dp"
- android:layout_gravity="center_horizontal">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:text="Large Text"
- android:id="@+id/textView1" />
- </LinearLayout>
- </LinearLayout>
- 08-29 14:52:39.285 1236-1236/android.process.acore W/Zygote? Slow operation: 5274 ms in ForkAndSpecializeCommon:Fork and detach
- 08-29 14:52:39.381 1236-1236/android.process.acore W/Zygote? Slow operation: 5443 ms in ForkAndSpecializeCommon:child process setup
- 08-29 14:52:40.009 1236-1236/android.process.acore W/Zygote? Slow operation: 6071 ms in ForkAndSpecializeCommon:PostForkChildHooks returns
- 08-29 14:52:40.013 1236-1236/android.process.acore W/Zygote? Slow operation: 7411ms so far, now at Zygote.nativeForkAndSpecialize
- 08-29 14:52:41.694 1236-1236/android.process.acore W/Zygote? Slow operation: 9095ms so far, now at Zygote.postForkCommon
- 08-29 14:52:41.756 1236-1236/android.process.acore W/Zygote? Slow operation: 9264ms so far, now at zygoteConnection.runOnce: postForkAndSpecialize
- 08-29 14:54:40.299 1236-1247/android.process.acore W/art? Suspending all threads took: 10.659s
- 08-29 14:55:54.233 1236-1260/android.process.acore I/art? WaitForGcToComplete blocked for 601.023ms for cause DisableMovingGc
- 08-29 14:56:48.346 1236-1260/android.process.acore I/ContactLocale? AddressBook Labels [en-US]: [, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, , ا, ب, ت, ث, ج, ح, خ, د, ذ, ر, ز, س, ش, ص, ض, ط, ظ, ع, غ, ف, ق, ك, ل, م, ن, ه, و, ي, , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, #, ]
- 08-29 14:56:48.729 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x16c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 14:56:48.729 1236-1239/android.process.acore I/art? [ 08-29 14:56:49.255 948: 966 E/ActivityManager ]
- ANR in com.android.phone
- PID: 1194
- Reason: executing service com.android.phone/.TelephonyDebugService
- Load: 9.14 / 6.53 / 4.95
- CPU usage from 1ms to 121124ms later with 99% awake:
- 41% 55/surfaceflinger: 13% user + 27% kernel
- 28% 948/system_server: 16% user + 11% kernel / faults: 6340 minor 1 major
- 4.6% 1194/com.android.phone: 2.7% user + 1.9% kernel / faults: 1668 minor
- 3.3% 715/zygote: 2.9% user + 0.4% kernel / faults: 1635 minor
- 3.1% 1209/com.android.launcher: 2.4% user + 0.6% kernel / faults: 2764 minor 1 major
- 2.5% 63/debuggerd: 0.5% user + 1.9% kernel / faults: 2144 minor
- 1.5% 1236/android.process.acore: 1.1% user + 0.3% kernel / faults: 906 minor
- 1.4% 1164/com.android.inputmethod.latin: 1% user + 0.3% kernel / faults: 923 minor
- 1.3% 1284/com.android.systemui: 0.8% user + 0.5% kernel / faults: 1759 minor
- 1% 25/mtdblock0: 0% user + 1% kernel
- 0.3% 26/mtdblock1: 0% user + 0.3% kernel
- 0.2% 714/mediaserver: 0% user + 0.1% kernel
- 0.1% 50/logd: 0% user + 0% kernel / faults: 6 minor
- 0% 53/servicemanager: 0% user + 0% kernel
- 0% 743/installd: 0% user + 0% kernel / faults: 7 minor
- 0% 1151/kworker/0:2: 0% user + 0% kernel
- 0% 42/jbd2/mtdblock1-: 0% user + 0% kernel
- 0% 51/healthd: 0% user + 0% kernel
- 0% 5/kworker/u:0: 0% user + 0% kernel
- 0% 39/flush-31:1: 0% user + 0% kernel
- 0% 61/adbd: 0% user + 0% kernel
- +0% 1303/<pre-initialized>: 0% user + 0% kernel
- +0% 1318/patchoat: 0% user + 0% kernel
- 100% TOTAL: 49% user + 50% kernel + 0% softirq
- CPU usage from 118480ms to 120630ms later:
- 66% 948/system_server: 38% user + 28% kernel
- 11% 966/ActivityManager: 5.6% user + 6.1% kernel
- 7% 965/android.bg: 2.8% user + 4.2% kernel
- 0.4% 962/Binder_2: 0.4% user + 0% kernel
- 0.4% 969/android.ui: 0.4% user + 0% kernel
- 15% 715/zygote: 13% user + 1.4% kernel / faults: 44 minor
- 15% 715/main: 13% user + 1.4% kernel
- 20% 1318/patchoat: 14% user + 6.4% kernel / faults: 187 minor
- 19% 1236/android.process.acore: 19% user + 0% kernel / faults: 66 minor
- 19% 1260/ContactsProvide: 16% user + 2.5% kernel
- 1.1% 26/mtdblock1: 0% user + 1.1% kernel
- 0.2% 51/healthd: 0% user + 0.2% kernel
- 100% TOTAL: 67% user + 32% kernel
- 08-29 14:59:21.434 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x16c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 14:59:21.434 1236-1239/android.process.acore I/art? [ 08-29 14:59:21.532 1379: 1379 W/Zygote ]
- Slow operation: 2621ms so far, now at Zygote.nativeForkAndSpecialize
- 08-29 14:59:59.940 1236-1239/android.process.acore I/art? Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:00:16.326 1236-1264/android.process.acore I/art? WaitForGcToComplete blocked for 428.524ms for cause DisableMovingGc
- 08-29 15:01:14.959 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x12c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 15:01:14.959 1236-1239/android.process.acore I/art? [ 08-29 15:01:15.066 1236: 1239 W/art ]
- Suspending all threads took: 106.226ms
- 08-29 15:04:09.112 1236-1249/android.process.acore W/libbacktrace? void ThreadEntry::Wait(int): pthread_cond_timedwait failed: Connection timed out
- 08-29 15:04:31.164 1236-1250/android.process.acore W/libbacktrace? void ThreadEntry::Wait(int): pthread_cond_timedwait failed: Connection timed out
- 08-29 15:05:51.798 1236-1239/android.process.acore I/art? Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:05:51.799 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x12c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 15:05:51.800 1236-1239/android.process.acore I/art? [ 08-29 15:06:19.968 948: 950 I/art ]
- Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:07:36.915 1236-1250/android.process.acore W/libbacktrace? void ThreadEntry::Wait(int): pthread_cond_timedwait failed: Connection timed out
- 08-29 15:08:12.196 1236-1261/android.process.acore W/libbacktrace? void ThreadEntry::Wait(int): pthread_cond_timedwait failed: Connection timed out
- 08-29 15:08:54.338 1236-1239/android.process.acore I/art? Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:08:54.339 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x12c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 15:08:54.340 1236-1239/android.process.acore I/art? [ 08-29 15:09:20.351 1413: 1417 I/art ]
- Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:11:45.413 1236-1239/android.process.acore I/art? Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:11:45.414 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x12c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 15:11:45.446 1236-1239/android.process.acore I/art? [ 08-29 15:11:45.576 1236: 1239 W/art ]
- Suspending all threads took: 129.303ms
- 08-29 15:12:38.757 1236-1239/android.process.acore I/art? Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:14:30.159 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x12c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 15:14:30.159 1236-1239/android.process.acore I/art? [ 08-29 15:14:30.359 948: 966 I/Process ]
- Sending signal. PID: 1614 SIG: 3
- 08-29 15:14:37.787 1236-1239/android.process.acore W/art? Suspending all threads took: 7.626s
- 08-29 15:14:48.777 1236-1239/android.process.acore I/art? Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:15:36.246 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x16c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 15:15:36.246 1236-1239/android.process.acore I/art? [ 08-29 15:15:36.377 948: 948 F/MediaSessionService ]
- Error sending default remote volume to sys ui.
- android.os.DeadObjectException
- at android.os.BinderProxy.transactNative(Native Method)
- at android.os.BinderProxy.transact(Binder.java:496)
- at android.media.IRemoteVolumeController$Stub$Proxy.updateRemoteController(IRemoteVolumeController.java:109)
- at com.android.server.media.MediaSessionService.pushRemoteVolumeUpdateLocked(MediaSessionService.java:492)
- at com.android.server.media.MediaSessionService.pushSessionsChanged(MediaSessionService.java:472)
- at com.android.server.media.MediaSessionService.access$3200(MediaSessionService.java:74)
- at com.android.server.media.MediaSessionService$MessageHandler.handleMessage(MediaSessionService.java:1113)
- at android.os.Handler.dispatchMessage(Handler.java:102)
- at android.os.Looper.loop(Looper.java:135)
- at com.android.server.SystemServer.run(SystemServer.java:269)
- at com.android.server.SystemServer.main(SystemServer.java:170)
- at java.lang.reflect.Method.invoke(Native Method)
- at java.lang.reflect.Method.invoke(Method.java:372)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
- 08-29 15:16:00.831 1236-1239/android.process.acore W/art? Suspending all threads took: 24.584s
- 08-29 15:17:06.697 1236-1239/android.process.acore I/art? Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:18:10.801 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x12c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 15:18:10.801 1236-1239/android.process.acore I/art? [ 08-29 15:18:11.000 948: 966 I/Process ]
- Sending signal. PID: 1209 SIG: 3
- 08-29 15:19:13.654 1236-1239/android.process.acore I/art? Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:19:13.673 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x12c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 15:19:13.674 1236-1239/android.process.acore I/art? [ 08-29 15:19:19.456 1236: 1239 I/art ]
- Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:26:07.682 1236-1239/android.process.acore I/art? Thread[2,tid=1239,WaitingInMainSignalCatcherLoop,Thread*=0xb4827c00,peer=0x12c070a0,"Signal Catcher"]: reacting to signal 3
- 08-29 15:26:07.683 1236-1239/android.process.acore I/art? [ 08-29 15:26:07.870 1236: 1239 W/art ]
- Suspending all threads took: 186.047ms
- 08-29 15:27:23.310 1236-1239/android.process.acore I/art? Wrote stack traces to '/data/anr/traces.txt'
- 08-29 15:27:25.097 1236-1236/android.process.acore I/art? Explicit concurrent mark sweep GC freed 39(13KB) AllocSpace objects, 0(0B) LOS objects, 61% free, 647KB/1671KB, paused 3.812ms total 1.734s
- 08-29 15:42:12.571 1236-1241/android.process.acore W/art? Suspending all threads took: 5.197ms
- 08-29 15:54:12.363 1236-1241/android.process.acore W/art? Suspending all threads took: 5.162ms
- 08-29 15:54:40.611 1236-1241/android.process.acore W/art? Suspending all threads took: 210.660ms
- 08-29 15:54:41.768 1236-1241/android.process.acore W/art? Suspending all threads took: 231.506ms
- 08-29 15:54:42.649 1236-1241/android.process.acore W/art? Suspending all threads took: 148.303ms
- 08-29 15:54:44.440 1236-1250/android.process.acore V/BackupServiceBinder? doBackup() invoked
- 08-29 15:54:44.528 1236-1250/android.process.acore E/DictionaryBackupAgent? Couldn't read from the cursor
- 08-29 15:55:34.947 1236-1241/android.process.acore W/art? Suspending all threads took: 5.142ms
- 08-29 15:55:38.611 1236-1241/android.process.acore W/art? Suspending all threads took: 175.911ms
- 08-29 15:55:52.396 1236-1241/android.process.acore W/art? Suspending all threads took: 203.407ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement