title: How to access SQlite returned data globally in Android?
body: <pre><code>public class MainObj {
      private static final MainObj instance = new MainObj();
  
      public static MainObj getInstance() {
          return instance;
      }
  
      public static class User {
          public int account_id;
          public String user_id;
          public String sip_id;
          public String username;
          public String fullname;
          public boolean active;
          public boolean status;
  
          public int getAccount_id() {
              return account_id;
          }
          public void setAccount_id(int account_id) {
              Log.e("myphone", account_id+"");
              this.account_id = account_id;
          }
          public String getUser_id() {
              return user_id;
          }
          public void setUser_id(String user_id) {
              this.user_id = user_id;
          }
          public String getSip_id() {
              return sip_id;
          }
          public void setSip_id(String sip_id) {
              this.sip_id = sip_id;
          }
          public String getUsername() {
              return username;
          }
          public void setUsername(String username) {
              this.username = username;
          }
          public String getFullname() {
              return fullname;
          }
          public void setFullname(String fullname) {
              this.fullname = fullname;
          }
          public boolean isActive() {
              return active;
          }
          public void setActive(boolean active) {
              this.active = active;
          }
          public boolean isStatus() {
              return status;
          }
          public void setStatus(boolean status) {
              this.status = status;
          }
      }
  }
  </code></pre>
  
  <p>I write sip application on Android. I have some kind of information about user logged in. I want to make something like that.</p>
  
  <ol>
  <li>User object with user settings (stored in SQlite)</li>
  <li>Access user data from SQlite data and store in Object</li>
  <li>Use user data directly from Object like (in UI activity, fragment ...):</li>
  </ol>
  
  <pre>User user = new User();
  Log.i("TAG", user.sip_id);</pre>
  
  <p><strong>or</strong> </p>
  
  <pre>Log.i("TAG", user.getSip_id());</pre>
  
  <pre><code>// get user data from table
  public HashMap&lt;String, String&gt; getUserDetails() {
      HashMap&lt;String, String&gt; user = new HashMap&lt;String, String&gt;();
      String selectQuery = "SELECT * FROM user";
  
      SQLiteDatabase db = this.getReadableDatabase();
      Cursor cursor = db.rawQuery(selectQuery, null);
      cursor.moveToFirst();
  
      if (cursor.getCount() &gt; 0) {
          MainObj.User user = new MainObj.User();
          user.setSip_id(cursor.getString(1));
          user.setAccount_id(cursor.getString(2));
          .... and so on
      }
  
      cursor.close();
      db.close();
  
      // return user
      return user;
  }
  </code></pre>
  
  <p>I don't know how to google correctly, because i've searched about 3 hours.</p>