Questions tagged [android-application-class]

Extending Android's Application class can be very useful to maintain global state, initialise a module, and so on, before any other part of your code runs.

Android Developer Docs say:

Base class for maintaining global application state. You can provide your own implementation by creating a subclass and specifying the fully-qualified name of this subclass as the "android:name" attribute in your AndroidManifest.xml's <application> tag. The Application class, or your subclass of the Application class, is instantiated before any other class when the process for your application/package is created.

91 questions
170
votes
13 answers

Why extend the Android Application class?

An extended Application class can declare global variables. Are there other reasons?
TN888
  • 7,235
  • 9
  • 42
  • 82
26
votes
5 answers

Android 7.0 and 7.1 getApplication() ClassCastException

In Developer Console I see a lot of crashes with stacktrace like this java.lang.RuntimeException: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984) at…
Martin Vandzura
  • 2,979
  • 1
  • 27
  • 56
11
votes
1 answer

Android Architecture Components ViewModel Context

I'm studying google's architecture components to implement ViewModel and LiveData to my app, and the official documentation says that: Note: Since the ViewModel outlives specific activity and fragment instantiations, it should never reference a…
9
votes
2 answers

How to extend application class in xamarin android

I want to extend the Android application and I want to override oncreate method. But for some reason its been very terrible...Only if I remove [Application] I am able to run it but according to this link we have to add…
7
votes
0 answers

how to start android-TREBLE compatible vendor java service from /vendor/app

In my Android-O device, below two background services communicating each other though AIDL. Native/c++ android service Starts through init rc Runs with system linux-user Deployed in /system partition, eg, /system/bin/nat binary. Java Service from…
7
votes
1 answer

java.lang.VerifyError in Application class for a small percentage of users

(This is not a duplicate of other similar questions, as this only happens on a small percentage of users, and can't be recreated by me) In my latest production release, I suddenly see a huge peak in crashes of type java.lang.VerifyError coming from…
marmor
  • 25,207
  • 10
  • 99
  • 145
5
votes
0 answers

Android App Bundle check for missing splits causes "RuntimeException: Package manager has died"

I followed this guide to integrate a check into my app to prevent crashes at runtime when using Android App Bundles (for missing resources). I added the following code to my application class in the onCreate() method before the super call: if…
5
votes
0 answers

java.lang.ClassCastException when I try cast Application to MyApplication from a Fragment(Android 6+)

I have a fragment which extends android.app.Fragment. Inside onCreateView in some case I have java.lang.ClassCastException when I try cast Application to my implementation of Application. public class SketchFragment extends android.app.Fragment{ …
4
votes
5 answers

How do I enforce Application onCreate after app was closed and a service is running in the bg?

Basically I've got an application that runs a foreground service. When I start the application I need to do session specific initialization in the Application's onCreate method. When I close the app, the service keeps running (desired behaviour),…
3
votes
2 answers

How do I handle process recreation in android when application startup relies on a network call?

Say I have a custom application in class in my Android app that makes a network call, asynchronously, on startup. Then I have a Main activity that needs the results of the network call on startup. I can handle this with a Splash activity that…
3
votes
1 answer

How do I provide a custom Application class to my Espresso Activity test?

I'm pretty new to Espresso, but I am trying to test a relatively simple Activity. My android app has its own custom Application class. How can I tell Espresso to use a mocked (or custom) version of this class? Here is my custom version of the…
3
votes
1 answer

android.app.Application cannot be cast despite being mentioned in the Manifest

I have looked at all the solutions in StackOverflow, but all of them are telling to add android:name in the application tag, which I have already done I'm trying to experiment with Kotlin in Android app development. Here is my MainActivity class…
Sparker0i
  • 1,464
  • 3
  • 24
  • 45
3
votes
2 answers

Why do I have ClassNotFoundException on my app?

Background Not so long ago, Google has changed the Google Play Console, so that crashes are automatically being reported as soon as they occur, having it as part of what they call "Android Vital". From this day, I got many crash reports that I've…
3
votes
2 answers

getExtras() return null on Application level (-class)

On my Application level I receive null for getExtras(), but on Activity level i can see them correctly. public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Intent intent =…
2
votes
2 answers

Can't start junit test when application class is customized

When I try to start one of my junit tests, all of them fail due to multiple errors. This is due to the fact, that my Application class has some variables in it, which are initialized in the "normal" app start, but not when I start a test. Commenting…
1
2 3 4 5 6 7