I am reposting this Question:
I want my application to restart when pressing "OK" in an alertDialog. But when I am pressing the button I am getting "Complete Action USing" screen, how do I start my application without having to go to "Complete Action.." ?
And is it the right way to restart application?
P.S. I need to restart application because initially when the application starts the list is shown from the local database, then after getting the new data from server and updating local database, I can't display updated list. It works after restarting app.
Code for calling startActivity:
Toast.makeText(mContext, "Reading complete", Toast.LENGTH_SHORT).show();
AlertDialog.Builder clickAlert = new AlertDialog.Builder(mContext);
clickAlert.setMessage("Database has been updated, please restart application to load new data. ");
clickAlert.setPositiveButton("Restart", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent i = new Intent("android.intent.action.MAIN");
mContext.startActivity(i);
}
});
clickAlert.create().show();
I have a listFragment that gets populated from a String adapter and this this string is filled from a method which returns data from server. I need to repopulate this list. Code:
// Get a cursor containing storelist
Cursor curStoreList = mDbHelper.getStoreList();
String[] StoreList = new String[curStoreList.getCount()];
int i = 0;
// Store returned items in StoreList[]
while (curStoreList.moveToNext()) {
String storeName = curStoreList.getString(0);
StoreList[i] = storeName;
i++;
}
// Create an adapter with list of stores and populate the list with
// values
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, StoreList);
setListAdapter(adapter);