Note that there are some explanatory texts on larger screens.

plurals
  1. POusing getApplicationContext() in two threads
    primarykey
    data
    text
    <p>I have a main class "A". That calls a method in class "B". In class A I pass the parameter getAplicationContext() to the method in B.</p> <p>That method in "B" class is where <code>tempContext</code> is a Context object (Global):</p> <pre><code> public void backit(Context con) throws Exception { tempContext = con; Completion perThread; perThread = new Completion(); perThread.start(); } </code></pre> <p>The Completion Class is:</p> <pre><code>public class Completion extends Thread { ProgressDialog progDialog; int maxvalue; public void run() { maxvalue = BackupOperation.con_num; progDialog = new ProgressDialog(tempContext); Log.d("TEST", "HELLO"); } } </code></pre> <p>My application force closes. With exceptions:</p> <pre><code>12-04 22:41:28.984: W/dalvikvm(19517): threadid=10: thread exiting with uncaught exception (group=0x40af3228) 12-04 22:41:29.104: E/AndroidRuntime(19517): FATAL EXCEPTION: Thread-15840 12-04 22:41:29.104: E/AndroidRuntime(19517): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 12-04 22:41:29.104: E/AndroidRuntime(19517): at android.os.Handler.&lt;init&gt;(Handler.java:121) 12-04 22:41:29.104: E/AndroidRuntime(19517): at android.app.Dialog.&lt;init&gt;(Dialog.java:127) 12-04 22:41:29.104: E/AndroidRuntime(19517): at android.app.AlertDialog.&lt;init&gt;(AlertDialog.java:114) 12-04 22:41:29.104: E/AndroidRuntime(19517): at android.app.AlertDialog.&lt;init&gt;(AlertDialog.java:98) 12-04 22:41:29.104: E/AndroidRuntime(19517): at android.app.ProgressDialog.&lt;init&gt;(ProgressDialog.java:77) </code></pre> <p>I can figure out that <code>tempContext</code> when i refer it in the thread, my application force closes. Any suggestions on how to get the application context in that thread?</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.
 

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