In Android How to show message when data is Changed into Database?

I need to show the message in Android Java Class when the Data is Changed into the Database. What method has to be used to do this??

Please help me , I dont have any Idea about this.

This is my PHP Code:

    include '../../dbconnect.php';
    $oidquery="select orderid, orderstatus from din_orders where tableid=$tableid  &&      orderstatus!='Pending'";
     $oidquery="select orderid,orderstatus from din_orders where tableid=$tableid &&        orderstatus='$status'";
   echo json_encode(array('orders'=>$ordersarray));

For Example: In a Table "OrderStatus" Initially It shows as "Pending" later manually I will change "Pending" as "Delivered". When this change takes place in Database I should get a message in Android Java Class as "Items Delivered".

Here is my Android Java Code:

    public void ordersdisplay() {
    String selectedstatus1 = (String) status.getSelectedItem();
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
    nameValuePairs.add(new BasicNameValuePair("Tableid", tableid1));
    nameValuePairs.add(new BasicNameValuePair("Status", selectedstatus1));
    InputStream is = null;
    String result = "";
    JSONObject JArray = null;
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url + "order_status.php");
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpClient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    } catch (Exception e) {
        Log.e("log", "Error in Connection" + e.toString());
        Toast.makeText(getApplicationContext(), "Error in Connection",

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = "";
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        result = sb.toString();
    } catch (Exception e) {
        // TODO: handle exception

    try {

        JArray = new JSONObject(result);
        JSONArray jsonArray = JArray.getJSONArray("orders");

        for (int i = 0; i < jsonArray.length(); i++) {
            HashMap<String, String> map = new HashMap<String, String>();
            JSONObject jsonObject = jsonArray.getJSONObject(i);

            map.put("orders", String.valueOf(i));
            map.put("orderid", jsonObject.getString("orderid"));
            map.put("status", jsonObject.getString("orderstatus"));

    } catch (JSONException e) {
        Toast.makeText(getApplicationContext(), "No Order to Display",

        Log.e("log_tag", "Error parsing data " + e.toString());
    ListAdapter adapter = new SimpleAdapter(this, mylist,
            R.layout.vieworder, new String[] { "orderid", "status" },
            new int[] {, });


    final ListView lv = getListView();
    lv.setOnItemClickListener(new OnItemClickListener() {
        public final void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            HashMap<String, String> o = (HashMap<String, String>) lv

            String OrderID = o.get("orderid");
            String OrderStatus = o.get("status");
            Intent intent = new Intent(getApplicationContext(),
            intent.putExtra("orderid", OrderID);
            intent.putExtra("waitername", waitername);
            intent.putExtra("orderstatus", OrderStatus);
            intent.putExtra("tableid", tableid1);
            intent.putExtra("url", url);




If you are inserting values in SQLite database like following

ContentValues values = new ContentValues();
database = dbHelper.getWritableDatabase();
database.insert(DBHelper.TABLE_NAME, null, values);

Here database.insert returns the row ID of the newly inserted row, or -1 if an error occurred.

So you can have following validation.

if (database.insert(DBHelper.TABLE_NAME, null, values) != -1)
  Toast.makeText(this, "Write Success", Toast.LENGTH_SHORT).show();
 Toast.makeText(this, "Write Failure", Toast.LENGTH_SHORT).show();

If the insertion failed, odds are you will receive an error. However if you want to double check: simply query the database for the new, unique data. If your Cursor does not return empty then the insertion succeeded.

have a look at or services simple php function you can place in an IF statement wrapper if insert/update is successful.

I use this for checking my mysql db is available.

Need Your Help

Android ImageView doesn't wrap content

android imageview tablelayout

Cannot solve trouble with ImageView inside of the TableLayout.

Intercepting a push notification when the app is not in foreground or background

push-notification swift2

My app handles/intercepts push notifications correctly in the following scenarios: