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
0
votes
0 answers

Activity created before Application.onCreate called?

We use a subclassed Application object, like this: class MyApp : Application() { init { instance = this } ... companion object { lateinit var instance: MyApp private set } } ...which should get…
Dmitry Brant
  • 7,612
  • 2
  • 29
  • 47
0
votes
0 answers

Android system theme DarkMode/LightMode change call back at run time

I want to get the current theme of the app and I am doing it as shown below, when (this.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)) { Configuration.UI_MODE_NIGHT_YES -> onThemeChange(Themes.DARK) …
0
votes
1 answer

Identifying how an android app's application class is launched

I have some code in my Application class that needs to be run whenever the app is launched. However my app also has some service running and because of that, whenever the service is invoked the code in my Application class also runs. I want to…
0
votes
1 answer

Android Application class killed and starts periodically

I am working on an Android application that most it logic is done in background and basically analyzing the user activities (walking, running, in_vehicle etc).. The ui has only 2 screens for basic setup and for giving permissions. In the Application…
Moti Bartov
  • 3,454
  • 33
  • 42
0
votes
1 answer

add data to listview from another activity

I'm really confused on how to add from another activity I keep getting an error in this part of the code: Emails a = new Emails(intent.getStringExtra("inputEmail"), intent.getStringExtra("inputBody"), intent.getStringExtra("inputSubject")); So the…
0
votes
1 answer

App stops Caused by Attempt to invoke interface method 'int java.util.List.size()' on a null object reference

How to Fix this code? It keeps closing the app for these reasons in logcat? Error that I got is in here It keeps on crashing or stopping everytime i run it. I do not have build errors but i checked my logcat for the reason and still cant resolve…
0
votes
2 answers

how should i add sound in android studio which plays on button click

this is my code fun onclick(view: View) { val numberRandom = (1..6).random() textView1.text = "$numberRandom" var mediaPlayer: MediaPlayer? = MediaPlayer.create(this, R.raw.rolll.wav) mediaPlayer?.start() // no need to call…
0
votes
2 answers

Reading data from Android App using bluetooth

I have Java code to receive data in Android App via Bluetooth like the attached code Java Code so readMessage will equal = {\"Pin\":\"A4\",\"Value\":\"20\"},{\"Pin\":\"A5\",\"Value\":\"925\"},{\"Pin\":\"A0\",\"Value\":\"30\"} So I want to take only…
0
votes
1 answer

Create application class dynamically in Android

I have a 3rd party library that exposes its functionality through a listener interface. The requirement of the library is that it gets initialized in the onCreate of the custom Android Application class. public class CustomApplicationWithListener…
luckysing_noobster
  • 1,933
  • 5
  • 24
  • 50
0
votes
1 answer

Custom AppComponentFactory Fails to Instantiate Application

I am attempting to implement a custom AppComponentFactory to create my Application and Activity instances using non-zero arg constructors (Dagger based constructor dependency injection), but my app fails to launch because my custom Application…
0
votes
1 answer

Run time permission from application

I want to ask for permission from the application class. How can I ask permission for accessing the device ID? I cannot ask for permission from activity as it crashes before starting the splash screen activity. The following code is part of splash…
0
votes
0 answers

How to grant permission in Application class Xamarin.Android?

I want to grant camera permission for the application using my Application class in my Xamarin.Android project. But I cannot call ActivityCompat.RequestPermissions(this, _mPerms, 1); within my Application class since this should be an Activity. So…
0
votes
1 answer

Can I expect my application's constructor to get executed completely before my service methods are invoked?

Coming straight to question, App_A -> binds with service in App_B App_B tries to init few values in it's application class constructor Can I expect App_B's Application class constructor to get executed completely before the service methods…
0
votes
0 answers

getApplicationContext() returns null when application instance is recreated

I'm trying to launch an activity using application's context something like this, This works public class MyApplication extends Application { public static Context mContext = null; public MyApplication() { mContext = this; } …
Tom Taylor
  • 3,344
  • 2
  • 38
  • 63
0
votes
1 answer

Why my application class which extends android.app.application is not working?

I have to call a print method from the test class whenever my application starts. I have called this print method from onCreate() of MyApplication class which extends android.app.application class. In the print() method, I am displaying a toast…
Shubh.J
  • 145
  • 1
  • 2
  • 12