I am working on application which is host on android market. Sometimes (once a month ) I got a crash report:
Unable to instantiate application java.lang.C
I think the problem is with getApplication() which I have used in 10 different place. So I have used singleton pattern to solve this.
public class MyApplication extends Application {
private static MyApplication me;
@Override
public void onCreate() {
super.onCreate();
me = this ;
}
public static MyApplication getInstance() {
return me;
}
}
Now I have used getApplication() like this
MyApplication application = MyApplication.getInstance();
insted of
MyApplication application = (MyApplication) getApplication();
I have uploaded the fixed version on the market & now waiting if there is anymore this kind of crash. If everything goes perfect ( if no more crash in 2 weeks) then I will close the question. In meanwhile anyone has better idea or know the solution , please share it.
Thanks,