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

Android: extending Application class. Why do we need to implement singleton pattern?

I'd like to put my database connection object to Application class. I read some tutorials and everywhere I see explicit implementation of a singleton pattern. Something like this public class MyApplication extends Application { private static…
Vitalii
  • 10,091
  • 18
  • 83
  • 151
0
votes
0 answers

Multiple Application Classes by Extension

I wanted to have multiple Application Classes just to clean up my code. So I created 4 classes. 1.A General Class for future references: public class GlobalVariables extends Application { } A Times Class for my time functions: public class…
0
votes
0 answers

Android: start an AndroidApplication class

In my activity I want to start a class which extends an AndroidApplication class but I don't know how to do it. I want to call the onCreate method of the AndroidApplication class, of course. public class MainActivity extends…
Tosch
  • 17
  • 4
0
votes
1 answer

Error: incompatible types: Application cannot be converted to AnalyticsApplication.: Android Studio 2.3.2

I updated my Android Studio to 2.3.2 after which the gradle build fails with the below error: error: incompatible types: Application cannot be converted to AnalyticsApplication. I have tried searching about it but could not find anything…
manini
  • 358
  • 1
  • 4
  • 14
0
votes
1 answer

Close android application when mobile sleep after timeout or when power button is pressed

I am creating a locker application, in which I want to close my application when user presses power button to lock screen or when screen off after timeout. I have tried to do this using onResume(), onPause() function but nothings works perfect.
0
votes
2 answers

How to store data in a image viewing android app?

I am trying to create an app that shows a list of picture(with pagination) from an API, and when you click on a photo, it opens the photo (probably in a new activity) with zooming and stuff. My question is how should I store the API responses?…
Louis Tsai
  • 1,587
  • 3
  • 20
  • 33
0
votes
0 answers

application class return nullpointer

its my AplicationClass ==> @Override public void onCreate() { super.onCreate(); mydRef = FirebaseDatabase.getInstance().getReference(); tipDondur(); } public static Context context() { return app.getApplicationContext(); } public…
golbasi
  • 1
  • 2
0
votes
0 answers

"Firebase API initialization failure." when extending Application class and using Firebase in Android

I am integrating Firebase Cloud Messaging Service in my Android app. Currently my app extends the Application class (named as MainApplication) and is declared in manifest application tag. I have followed all the instructions to enable Firebase Cloud…
0
votes
0 answers

Android disable back button in class that extended Application Class

I have a class that extended Application Class I wondering if there is any way I could disable back button here?
0
votes
1 answer

Can I show physical layout of Application class to Users?

I read that a class that extends application is first run when my app is opened by my user. So I'm trying to give my application class a layout, so it may looks like a splash screen. But setContentView() is not working on class that extends…
0
votes
1 answer

Converting Android application to android library gives Error: constant expression required

I have an Android application which I wish to convert to a library to use in another application. I have changed com.android.application to com.android.library in the apply plugin section in gradle file. Removed application id. Removed the Launcher…
Arka Prava Basu
  • 2,366
  • 3
  • 18
  • 34
0
votes
1 answer

Adding multiple application class in AndroidManifest

My android app was needed to add multiDexApplication support. But Now I need to add another custom application class. How can I do that? //Here's My manifest code:
Soumya Rauth
  • 1,163
  • 5
  • 16
  • 32
0
votes
1 answer

service don't stop in fragment that start in application class

i'm developing a translator app and for some reasons i want to initiate some service in Application Class. i create a "MyApplication" class that extends Application: public class MyApplication extends Application{ @Override public void onCreate() { …
0
votes
1 answer

Extended Application can not run correctly

everyone. I am new to android. Recently, I tried to learn how to extend Application, but there is a strange problem. I have tried a lot of methods, but still can not solve it. So, thanks in advance if anyone can help me. The code section is like…
xing
  • 95
  • 1
  • 12
-1
votes
1 answer

Is it possible to access Context, Application, Activity anywhere statically?

So the question is, is it really possible to access Context, Application and specially Activity anywhere. Like as in other static class methods without passing parameters? Eg: public static class YOUR_CLASS{ public static void YOUR_FUNCTION(){ …