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.

97 questions
3
votes
2 answers

Is extending Application how you run code before the launching Activity?

If I do something like this: public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); //init something else here if you want } @Override public void onTerminate() { …
The 29th Saltshaker
  • 671
  • 1
  • 6
  • 16
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
1 answer

Android - Is it correct to overload the Application class constructor in kotlin?

Someone proposed to implement something as this in the main Application class: class MyApplication(someProp = SomeClass()): Application { init { ... do some initializations } } I have always used the OnCreate method to perform all…
htafoya
  • 18,261
  • 11
  • 80
  • 104
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…
Andrew
  • 4,264
  • 1
  • 21
  • 65
2
votes
1 answer

Android : How to dynamically change Locale for application level resources?

To change the locale, I am using method of creating a new Context and passing it into #super.attachBaseContext. This works fine for the Activities, since in my use-case it is applicable in the initial activities before the main workflow starts, so…
ashwin mahajan
  • 1,654
  • 5
  • 27
  • 50
2
votes
1 answer

Is there any way to show a global Dialog in android?

I need to show and maintain a dialog that disappears after a certain period of time(example: 30 s) on the Android Application. But I encountered some difficulties: how to record the showing time when host(is always activity) is destroyed or is…
2
votes
7 answers

How to unregister broadcast receiver from an Application Class?

I register broadcast receiver in Android's Application Class,but now my question is where to unregister that broadcast ? public class MyApplication extends Application { @Override public void onCreate() { ..... // OTHER…
2
votes
1 answer

NotificationListenerService called before Application.onCreate code

I have a NotificationListenerService implementation in my app. It seems that certain things that I initialize in my Application class are not initialized when my NotificationListenerService runs. Also, crashes are not coming into Crashlytics, but…
2
votes
1 answer

Android Application class method onCreate being called lately

I've overloaded the Application class in my android app and i'm usingIAviaryClientCredentials` interface. public class AppypieApplication extends Application implements IAviaryClientCredentials { public ArrayList bis; public…
Maveňツ
  • 1
  • 12
  • 50
  • 89
2
votes
2 answers

Android - Service or IntentService?

I have an app that runs certain "long" process when it is opened or when the device is booted. The process performs certain amount of downloads via the download manager, and when the process finishes it sends a broadcast event to the app, to capture…
2
votes
2 answers

Call activity from Application

I am trying to use Digits from Twitter. The AuthCallBack is not fired when used from activity and the recent document saying to use the AuthCallBack from the Application class. Now I have the AuthCallBack working correctly and onSuccess I need to…
1
vote
1 answer

App Startup library and long-running tasks in Application::onCreate

We recently integrated App Startup library into a project with a somewhat complex and time-consuming initialization logic that may take (in the worst case) up to several seconds. So we've got around 15 Initializers, some of them even trigger network…
fraggjkee
  • 3,524
  • 2
  • 32
  • 38
1
vote
0 answers

How can I use Hilt for module or library(aar)?

I am making a library. And I am using Hilt. The sample app is done and I am just trying to separate it as module to make it library later. However, Hilt needs to create Application and set like this: @HiltAndroidApp class MyApplication :…
c-an
  • 3,543
  • 5
  • 35
  • 82
1
vote
1 answer

How to display custom dialog on application launch?

Sometimes I want to display a dialog when the app launches. For that purpose I created a custom dialog named LoginDialog and I am using an Application class java. However, I am having trouble showing this dialog. For one I cannot call…
tmcb
  • 123
  • 1
  • 9
1
vote
2 answers

Will Application Class OnCreate be called if a Broadcast is recieved

I am using a JobIntentService perform some task after the task is ended I send a Broadcast which is also listened by one of my Activity. Suppose in a case where the activity is closed by Android OS to free up some memory then if the Broadcast is…