Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can handle screen rotation whilst executing a HTTP post?
    primarykey
    data
    text
    <p>I have a method which executes a HTTP post...</p> <p>When the user rotates the device during this process, it causes an ANR.</p> <p>Here is my code...</p> <pre><code>public void uploadTransactions(View v) { final ProgressDialog prog; try { // disable screen rotation setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); // setup progress dialog prog = new ProgressDialog(this); prog.setTitle("Uploading Transactions"); prog.setProgressStyle(ProgressDialog.STYLE_SPINNER); prog.setIcon(R.drawable.appicon); prog.setCanceledOnTouchOutside(false); prog.setCancelable(false); prog.show(); // setup thread for the sync Thread syncThread = new Thread(); syncThread = new Thread() { public void run() { String result = ""; String currentFileContents = ""; GetByREST gbr = new GetByREST(); String URL = //url for ReST service String URLparam = ""; String accountNo = //authorisation info String emailAddress = //authorisation info String password = //authorisation info try { // loop through the files File file = new File(SALES_DIRECTORY); for (File thisFile : file.listFiles()) { currentFileContents = readTransactions(thisFile); updateProgress(prog, "Uploading " + thisFile.getName()); result = gbr.getRestOutput(URL, URLparam, accountNo, emailAddress, password, "3", new StringEntity(currentFileContents)); } prog.dismiss();//dismiss the dialog // ...re-enable rotation setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } catch (Exception e) { messageBox("uploadTransactions: syncThread", e.getMessage()); } } }; syncThread.start(); } catch (Exception e) { messageBox("uploadTransactions", e.getMessage()); } } </code></pre> <p>This works fine if the screen is in portrait but, when in landscape, the orientation returns to portrait and causes an ANR. How can I get around this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload