You need to instance of your Application Class (ACRA) where ever you are
using.

//some thing like this.
ACRA acraapplication; //class variable, could be in
dbhandler,broadcastreceiver where ever u want.


//your method. could be onReceive, or anymethod u wanted to use it.

acraapplication = ((ACRA) getApplicationContext());

Warm Regards,
*Mukesh Kumar*,
Android Consultant/Freelancer,
India,Hyderabad.



On Wed, Jan 4, 2012 at 12:38 PM, Nikolay Elenkov
<[email protected]>wrote:

> There was a recent thread that states that there is only one Application
> instance
> per-APK-per-process. Therefore, Application#onCreate() should be called
> only
> once, but I am getting an error that suggest it's called twice: once from
> the app,
> and once from a widget broadcast receiver. Is this expected behaviour? Or
> am I
> missing something? Details below:
>
> I use ACRA for error reporting which checks if it is initialized only once
> with this
> code:
>
> public class ACRA {
>
>     private static Application mApplication;
>
>     public static void init(Application app) {
>         if (mApplication != null) {
>             throw new IllegalStateException("ACRA#init called more than
> once");
>         }
>      ...
>      }
> ...
> }
>
>
> (Full code here:
> http://code.google.com/p/acra/source/browse/trunk/acra/src/main/java/org/acra/ACRA.java
> )
>
> My application class simply calls this from onCreate():
>
> public class MyApplication extends Application {
>   public void onCreate() {
>     ACRA.init(this);
>   }
> }
>
> Here's the error:
>
> RuntimeException: Unable to start receiver MyWidgetProvider:
> java.lang.RuntimeException:
> Unable to create application MyApplication:
> java.lang.IllegalStateException: ACRA#init called more than once
>
> Part of trace leading to this:
>
> at MyApplication.onCreate(MyApplication.java:77)
> at
> android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
> at android.app.LoadedApk.makeApplication(LoadedApk.java:476)
> at android.app.ActivityThread.handleReceiver(ActivityThread.java:1791)
>
> This is happening on Android 2.3.3 and 2.3.4.
>
> Any ideas?
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




--

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to