Search code examples
androidandroid-activityandroid-listfragment

Restarting application using calling startActivity() but getting “complete action using”


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);

Solution

  • Actually,

    android.intent.action.MAIN
    

    is a Intent Action Name not any Activity name.

    You have to use Activity name which you want to start instead of it..

    like,

    Intent intent = new Intent(<Current_Activity>.this, <Starting_Activity>.class);
    

    Update:

    And what you want to achieve by android.intent.action.MAIN is for general Action Name for all application in Android.

    If you want to starting Activity using Intent Action Name then you have to define your own Intent Action Name in Activity Tag in Manifest file of your Application.

    Look at this SO Question How can I start MAIN activity with the help of <intent-filter>?