title: Data refresh in listview after adding data to database
body: <p>I have an application wherein, it retrieves data from DB and displays it in a list view but I want it to refresh after adding new data to database without using:</p>
  
  <pre><code>Intent i = new Intent (MyActivity.this,MyActivity.class);
  startActivity (i);
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  //DB Class to perform DB related operations
  DBController controller = new DBController(this);
  //Progress Dialog Object
  ProgressDialog prgDialog;
  EditText userName;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      userName = (EditText) findViewById(R.id.userName);
  
      //Get User records from SQLite DB
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; userList = controller.getAllUsers();
      //
      if (userList.size() != 0) {
          //Set the User Array list in ListView
          ListAdapter adapter = new SimpleAdapter(MainActivity.this, userList, R.layout.view_user_entry, new String[]{"userId", "userName"}, new int[]{R.id.userId, R.id.userName});
          ListView myList = (ListView) findViewById(android.R.id.list);
          myList.setAdapter(adapter);
          //Display Sync status of SQLite DB
          Toast.makeText(getApplicationContext(), controller.getSyncStatus(), Toast.LENGTH_LONG).show();
      }
      //Initialize Progress Dialog properties
      prgDialog = new ProgressDialog(this);
      prgDialog.setMessage("Synching SQLite Data with Remote MySQL DB. Please wait...");
      prgDialog.setCancelable(false);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.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();
      //When Sync action button is clicked
      if (id == R.id.refresh) {
          //Sync SQLite DB data to remote MySQL DB
          syncSQLiteMySQLDB();
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  //Add User method getting called on clicking (+) button
  public void addUser(View view) {
      Intent objIntent = new Intent(getApplicationContext(), NewUser.class);
      startActivity(objIntent);
  }
  
  public void syncSQLiteMySQLDB() {
      //Create AsycHttpClient object
      AsyncHttpClient client = new AsyncHttpClient();
      RequestParams params = new RequestParams();
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; userList = controller.getAllUsers();
  
      if (userList.size() != 0) {
          if (controller.dbSyncCount() != 0) {
              prgDialog.show();
              params.put("usersJSON", controller.composeJSONfromSQLite());
              client.post("http://192.168.2.4:9000/sqlitemysqlsync/insertuser.php", params, new AsyncHttpResponseHandler() {
                  @Override
                  public void onSuccess(String response) {
                      System.out.println(response);
                      prgDialog.hide();
                      try {
                          JSONArray arr = new JSONArray(response);
                          System.out.println(arr.length());
                          for (int i = 0; i &lt; arr.length(); i++) {
                              JSONObject obj = (JSONObject) arr.get(i);
                              System.out.println(obj.get("id"));
                              System.out.println(obj.get("status"));
                              controller.updateSyncStatus(obj.get("id").toString(), obj.get("status").toString());
                          }
                          Toast.makeText(getApplicationContext(), "DB Sync completed!", Toast.LENGTH_LONG).show();
                      } catch (JSONException e) {
                          // TODO Auto-generated catch block
                          Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
                          e.printStackTrace();
                      }
                  }
  
                  @Override
                  public void onFailure(int statusCode, Throwable error,
                                        String content) {
                      // TODO Auto-generated method stub
                      prgDialog.hide();
                      if (statusCode == 404) {
                          Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
                      } else if (statusCode == 500) {
                          Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
                      } else {
                          Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]", Toast.LENGTH_LONG).show();
                      }
                  }
              });
          } else {
              Toast.makeText(getApplicationContext(), "SQLite and Remote MySQL DBs are in Sync!", Toast.LENGTH_LONG).show();
          }
      } else {
          Toast.makeText(getApplicationContext(), "No data in SQLite DB, please do enter User name to perform Sync action", Toast.LENGTH_LONG).show();
      }
  }
  
  
  
  
  
  /**
   * Called when Save button is clicked
   * @param view
   */
  public void addNewUser(View view) {
      HashMap&lt;String, String&gt; queryValues = new HashMap&lt;String, String&gt;();
      queryValues.put("userName", userName.getText().toString());
      if (userName.getText().toString() != null
              &amp;&amp; userName.getText().toString().trim().length() != 0) {
          controller.insertUser(queryValues);
  
      } else {
          Toast.makeText(getApplicationContext(), "Please enter User name",
                  Toast.LENGTH_LONG).show();
      }
  }
  
  @Override
  protected void onResume() {
      super.onResume();
  }
  }
  </code></pre>