I'm getting data form url which is in json format my app is online now and I want to convert it to offline, So how will I get url from local database? How to make the application offline is it possible to insert all json form url into the database and then fetch it from local database using same query ? My application activities is having the same type classes get data from url. I'm geting data only once then use a local database? In my url there are some condition with respect to schoolId school leveled so how will I do this with the local database I'm confused to help me to make my application offline
{"status":1,"data":[{"title":"Atypical"}]}
public class MenuGroup extends Activity {
String status;
Menugroupscreenadapter mma;
String SelectMenuAPI;
String SelectMenuAPI2;
// String School_name;
String elementry;
String schedule_id, semestertitle, start_date, end_date;
ProgressBar prgLoading;
TextView txtAlert ,NoMenuAvailable ;
int IOConnect = 0;
ListView listmenusgroups;
String School_name;
long School_ID;
String URL,URL2;
String SchoolLevelId;
String menutype;
TextView Elementarytxt, Middletxt, Hightxt, Atypicaltxt;
static ArrayList<Long> Category_ID = new ArrayList<Long>();
static ArrayList<String> Category_name = new ArrayList<String>();
static ArrayList<Long> Menu_ID = new ArrayList<Long>();
String _response;
String Elementarytxtview,Middletextview,Hightextview,Atipicaltextview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menugroup);
Intent iGet = getIntent();
listmenusgroups = (ListView) findViewById(R.id.listmenusgroups);
mma = new Menugroupscreenadapter(this);
new getDataTask().execute();
listmenusgroups.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
Intent iMenuList = new Intent(MenuGroup.this, thirdstep.class);
iMenuList.putExtra("Menu_ID", Menu_ID.get(position));
iMenuList.putExtra("menu_group", Category_name.get(position));
startActivity(iMenuList);
}
});
}
public class getDataTask extends AsyncTask<Void, String, String>{
getDataTask(){
if(!prgLoading.isShown()){
}
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
}
@Override
protected String doInBackground(Void... arg0) {
// TODO Auto-generated method stub
SelectMenuAPI = Utils.menugroups+School_ID+"&lid="+SchoolLevelId+"&menu=no";
URL = SelectMenuAPI;
URL2 = URL.replace(" ", "%20");
try {
Log.i("url",""+URL2);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(URL2);
HttpResponse response = client.execute(request);
HttpEntity resEntity = response.getEntity();
_response=EntityUtils.toString(resEntity);
}
catch (IOException e) {
// TODO Auto-generated catch block
IOConnect = 1;
e.printStackTrace();
}
return _response;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
prgLoading.setVisibility(8);
listmenusgroups.setVisibility(0);
try {
JSONObject json2 = new JSONObject(result);
status = json2.getString("status");
if (status.equals("1")) {
JSONArray school = json2.getJSONArray("data");
for (int i = 0; i < school.length(); i++) {
JSONObject object = school.getJSONObject(i);
Category_ID.add((long) i);
Menu_ID.add(Long.parseLong(object.getString("menu_id")));
Category_name.add(object.getString("menu_title"));
}
}
else {
NoMenuAvailable.setVisibility(View.VISIBLE);
NoMenuAvailable.setText("No Menu Available for this School.");
listmenusgroups.setVisibility(View.GONE);
}
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
txtAlert.setVisibility(0);
}
listmenusgroups.setAdapter(mma);
}
}