Note that there are some explanatory texts on larger screens.

plurals
  1. POasyncantask with asyntask with background process
    text
    copied!<p>The following code gives a Force Close Error</p> <pre><code> public class MainActivity extends Activity { Button b1; TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1 = (Button) findViewById(R.id.button1); tv = (TextView) findViewById(R.id.textView1); b1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub new loadSomeStuff().execute(); } }); } public class loadSomeStuff extends AsyncTask&lt;String, Integer, String&gt; { ProgressDialog dlg; protected void onPreExecute() { dlg = new ProgressDialog(MainActivity.this); dlg.setProgressStyle(ProgressDialog.STYLE_SPINNER); dlg.setMessage("Loding Please Wait"); dlg.setMax(100); dlg.show(); } @Override protected String doInBackground(String... params) { // TODO Auto-generated method stub for (int i = 0; i &lt; 20; i++) { try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream( Environment.getExternalStorageDirectory() + "/" + "/bg.pdf")); document.open(); document.add(new Paragraph("hie")); Toast.makeText(getApplicationContext(), "Generated", Toast.LENGTH_LONG).show(); document.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } publishProgress(5); try { Thread.sleep(88); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } dlg.dismiss(); return null; } protected void onProgressUpdated(Integer... progress) { dlg.incrementProgressBy(progress[0]); } protected void onPostExecute(String result) { tv.setText("DONE"); } } </code></pre>
 

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