Android Question setDefaultNightMode before activity onCreate()

ArminKh1993

Active Member
hi

Sometimes we need to apply a theme other than the phone's default theme
for example: phone's theme is Dark(night) and i want to set Light theme programmatically when my app starts
as @Erel said in THIS thread we can use "setDefaultNightMode"
but this is not enough when an activity created, because a dark theme is always seen(about 100 miliseconds) before the light theme is displayed and It doesn't look attractive
you tries to solve this problem by using the hooks at "changing the theme at runtime" tutorial
and If I understand correctly, I must use this code to do this
B4X:
#if java
import androidx.appcompat.app.AppCompatDelegate;
public void _onCreate() {
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
#end if
but still a dark theme seen before switching to light

i found something like this over internet
B4X:
protected void onCreate(Bundle savedInstanceState) {
     AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
}
Which points to this ===> Use setDefaultNightMode before super.onCreate
but when i tries to override this method by using inline java, it seems B4A is used this function internally and i can't have access to this method in my code
how can i to do?
is this possible to run setDefaultNightMode before super.onCreate method in b4a? or some thing similar
It's really nerve-wracking for me
thanks all in advance
 
Top