I want to keep the state of some objects and that these objects would be available everywhere.

Created such a class.

package com.uilmorcraft.uilmorlibrary; public class App extends Application { @Override public void onCreate() { super.onCreate(); Log.v("APPLICATION", "onCreate()"); } } 

In the manifesto prescribed as follows.

  <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.uilmorcraft.uilmorlibrary"> <uses-feature android:name="android.hardware.location.network " /> <uses-feature android:name="android.hardware.location.gps" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <application android:name=".App" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> ... </application> </manifest> 

Logically, onCreate should be called at least once. But nothing happens. Yes, put a breakpoint.

I tried to change the manifest so

 <application android:name="com.uilmorcraft.uilmorlibrary.App" 

or so

 <application android:name="App" 

effect zero.

Created a new application. I did the same thing about the miracle. Everything is working.

The project is large and somehow hard to transfer all the code from the old to the new project for the sake of the working class Application. But I think that after the transfer I can get the same thing.

Can anyone come across this?

  • The problem may be in InstantRun . Try to disable it in the studio settings - YuriySPb
  • InstantRun has really influenced the work of the Appllication class. What could be the reason? After all, another application works fine with InstantRun. Yes, and InstantRun itself gives a good opportunity not to reassemble the application once again. - UilmorCraft
  • Most likely InstantRun ignored the changes in the manifest. The answer is written in more detail. In order not to stumble in the future on other limitations of this function - just turn it off. It is not worth using it - Yuriy SPb

1 answer 1

InstantRun feature allows you to see changes in the application without rebuilding / restarting it, which reduces development time.

But this feature can never work in all cases. For example, if you use to-liter using code generation, such as Realm , Dagger etc, changes to their use cannot be displayed using InstantRun , since require rebuilding the application in order to generate a new code for compilation.

In addition to the limitations mentioned above, InstantRun itself InstantRun far from perfect and can ignore even the simplest changes. Those. you can change the value of the variable to -l and then spend hours trying to understand why your bug fix did not fix the bug.

Thus, all the advantages of InstantRun completely leveled by the fact that it cannot be trusted and its behavior is unpredictable.

Conclusion:

Do not use InstantRun .