2

I am creating an app MainActivity that can calculate a report from its database to be shown in ReportActivity. All report calculation is done in ReportActivity.onCreate().

When the user click on MainActivity-s menu "generate report" the menü remains open for 2 secs until ReportActivity.onCreate() has finished and the report becomes visible.

What is the easiest way to give the user some visual feedback?

I already found ProgressDialog onCreate that shows a progressdialog while doing all calculation in an AsyncTask.

I wonder if there is some easier way to give the user some visual feedbak that the menue was successfully clicked and that the device has not crashed.

in ms windows i would use a waitcursor (hour-glass)

I already tried to open a ProgressDialog() in oncreate of the ReportActivity

    final ProgressDialog progressDialog = ProgressDialog.show(this, "MY Dialog", "Please wait...");

but it is not shown at all.

Update final solution:

As the answerss suggested I implemented an AsyncTask for the processing following this tutorial based on this codesample

Community
  • 1
  • 1
k3b
  • 14,517
  • 7
  • 53
  • 85

3 Answers3

2

You need to move your long-running code into a background thread. Long-running code on the UI thread will lock up the UI, which causes the user to think the app is frozen/crashing. Look into using AsyncTask. This allows you to run a process on a background thread and also give visual feedback to let the user know that your app is working.

Jason Robinson
  • 31,005
  • 19
  • 77
  • 131
1

Design a layout with ProgressDialog. Use setContentView(Progressdialog). Count time for 2-4 seconds (you choice) again set your older layout in setContentView. Why don't you use AsyncTask?

Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
1

Use a bar or circle activity indicator. From the official design guide:

Activity indicators are for operations of an indeterminate length. They ask users to wait a moment while something finishes up, without getting into specifics about what's happening behind the scenes.

Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127