Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6232137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:03:56+00:00 2026-05-24T10:03:56+00:00

I have a problem with a menu button called Refresh that lags for a

  • 0

I have a problem with a menu button called “Refresh” that lags for a long time when pressed. Basically, I’m running an async task that downloads xml from a web page and processes it and then finally updates the current list view. Is there some way to prevent this lag or refactor my code to make it more efficient?

Here is my activity where the refresh problem happens:

public class RouteView extends ListActivity implements ActivityUpdater {
private static ArrayList<String> mRouteNames;
private final String TAG = getClass().getName();
private TextView mTv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.route_view);

    ListView lv = getListView();
    LayoutInflater inflater = getLayoutInflater();
    ViewGroup header = (ViewGroup) inflater.inflate(R.layout.header, lv, false);
    lv.addHeaderView(header, null, false);
    mTv = (TextView) findViewById(R.id.refresh_status);
    long start = System.nanoTime();
    fetchFeed();
    Log.i("MagicBusV2", "Time: " + (System.nanoTime() - start));
}

@Override
protected void onResume() {
    super.onResume();
    fetchFeed();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);
    menu.add(0, Constants.REFRESH_MENU_ID, 0, R.string.refresh).setIcon(R.drawable.refresh);
    return result;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean result = super.onOptionsItemSelected(item);
    switch (item.getItemId()) {
    case Constants.REFRESH_MENU_ID:
        long start = System.nanoTime();
        fetchFeed();
        Log.i("MagicBusV2", "Refresh time: " + (System.nanoTime() - start));
        break;
    }
    return result;
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Log.i(TAG, "id: " + (int) id);
    Log.i(TAG, "num_routes: " + mRouteNames.size());
    String routeName = mRouteNames.get((int) id);
    Intent intent = new Intent(this, StopView.class);
    intent.putExtra(Constants.ROUTE_NAME, routeName);
    intent.putExtra(Constants.STOP_VIEW_TYPE, Constants.STOPS_ROUTE);
    startActivity(intent);
}

public void refreshUI() {
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mRouteNames));
    getListView().setTextFilterEnabled(true); // allows users to type to filter results, need to inform them of this some way

    mTv.setText("Refreshed!");
}

public static void setRouteNames(ArrayList<String> route_names) {
    mRouteNames = route_names;
}

private void fetchFeed() {
    mTv.setText("Refreshing...");

    new RefreshFeedTask(this).execute("null");      
}

And here is my AsyncTask code:

public class RefreshFeedTask extends AsyncTask<String, Integer, Void> {
private ArrayList<Route> routes;
private TimeFeed feed;
private ActivityUpdater updater;
private Context mCtx;

public RefreshFeedTask(Context ctx) {
    mCtx = ctx;
    updater = (ActivityUpdater) mCtx;
    routes = new ArrayList<Route>();
    try {
        feed = new TimeFeed();
    } catch (MBusDataException e) {
        e.printStackTrace();
    }
}

protected Void doInBackground(String... route_name) {
    routes = feed.getRoutes();
    int num_routes = routes.size();
    if(route_name[0].equals("null")) {
        ArrayList<String> route_names_list = new ArrayList<String>(num_routes);
        for (int i = 0; i < num_routes; i++) {
            route_names_list.add(routes.get(i).getName());
        }
        RouteView.setRouteNames(route_names_list);
    } else if(route_name[0].equals("all_stops")) {
        ArrayList<Stop> stops = new ArrayList<Stop>();
        for (Route route : routes) {
            for (Stop stop : route.getStops()) {
                if(!stops.contains(stop)) {
                    stops.add(stop);
                }
            }
        }
        StopView.setStops(stops);
    } else if(route_name.length > 1) {
        Route route = feed.getRouteWithName(route_name[0]);
        StopDetailsView.setStop(route.getStopWithName(route_name[1]));
    } else if(route_name[0].equals("favorites")) {
        ArrayList<Stop> fav_stops = new ArrayList<Stop>();
        ArrayList<Favorite> allFavs = FavoritesStore.getInstance(mCtx).getAllFavorites();
        for (Favorite fav : allFavs) {
            Route route = feed.getRouteWithName(fav.getRouteName());
            if (route != null) {
                Stop stop = route.getStopWithName(fav.getStopName());
                if (stop != null) {
                    fav_stops.add(stop);
                }
            }
        }
        StopView.setStops(fav_stops);
    } else {
        StopView.setStops(feed.getRouteWithName(route_name[0]).getStops());
    }
    return null;
}

protected void onPostExecute(Void ignore) {
    updater.refreshUI();
}

Thanks for any help you can give. I apologize if I posted too much code; I wasn’t sure how much was needed to find potential problems.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:03:57+00:00Added an answer on May 24, 2026 at 10:03 am

    Look at the constructor of the TimeFeed class. Since you said, that you are downloading and parsing stuff, and I believe that you are perhaps doing those things in the constructor, it will obviously take some time to execute that statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a menu that uses SSIs, problem is the tag needs an id
I have the following problem / bug: I made a custom button-class (called CustomBlitButton)
I have a problem with flash content in IE7 being always over the menu
I have a small problem when im working with a menu and a list
Here's my problem: I have do create a menu/list of actions (which would be
I have a flash file menu i am having problem while link it to
I've run on a little problem today: I have a JS drop down menu
I have problem in some JavaScript that I am writing where the Switch statement
I have a problem and that is my SplashScreen I have. It is built
I'm trying to make an Options Menu Screen. When the menu button is pressed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.