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

Using an alternative Application() class for unit testing in android

I have created an Application object which turns off Stetho. I want to use during my tests, but I don't know how swap it for the original Application class. I suppose I have to add it to the android-manifest before testing, or mock one…
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,541
  • 5
  • 19
  • 40
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
  • 2,378
  • 1
  • 27
  • 48
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
  • 135
  • 1
  • 2
  • 10
0
votes
1 answer

How can I use two android application classes for UI and Android-service?

Currently in my app, I have an Android application class & in there I'm doing some initializations that use in application UI and some features. Also, I have an Android service, that runs in backgrounds with some events that doesn't need those…
0
votes
1 answer

Risk of Broadcast Receiver leak when registered in Application class

I am registering a Broadcast Receiver in the app's Application class' onCreate(). I basically want the receiver to be active as long as the app's process is active. In this was, any component of the app getting triggered will result in the receivers…
0
votes
1 answer

Robolectric dosen't calling Application.onCreate(), and I cannot get context

Hello I have the following project structure --App |--SDK1 |--SDK2 In app I have some test for check SDK1 and SDK2. In SDK I have a singleton pattern only to set the context by the application class that is in App. And the context is set in…
0
votes
2 answers

Application crash when i add the name in application tag in manifest file

I am working on notification so i want to create channels at start app when oncreate method is called. SO when i add the name of the application class in application tag of Application class. When i remove it run fine. I ams using notification for…
0
votes
1 answer

Application in kotlin enum

Is it safe if I use application in a kotlin enum? Like this: enum class Labels(title: String, type: Int) { PERFORM(App.application.getString(R.string.perform), 0), DUTY(App.application.getString(R.string.duty), 1), ... ... }