1,969 questions
3
votes
1
answer
130
views
Why does gathering the app list from PackageManager & tapping any one cause the UI to freeze?
I'm developing an Android app that gathers a list of currently installed apps, both system & user-installed, and displays them on screen via LazyColumn using a Card composable. And when the user ...
0
votes
0
answers
40
views
What does this@class mean in Kotlin?
I see several examples, such as in this sample code in the Android dev documentation or this blog post, which suggests that the way to get an Activity context is to use the syntax this@MainActivity. ...
-1
votes
1
answer
44
views
how do a Context in Android
i m french and my english is not good,so i use google to translate,sorry for mistakes
I've been stuck on a problem for quite some time
here you go: I'm looking to make a small application that makes ...
1
vote
0
answers
52
views
Android Hilt pass Activity/intentExtras in Singleton Provide function
I'm new to Hilt/Dagger. I have an existing project with a Singleton, and I need a parameter from the caller app stored in intent extras:
@Module
@InstallIn(SingletonComponent::class)
class MyModule
{
...
0
votes
1
answer
35
views
stale preferences in WallpaperService
I'm a beginner in Android development. I'm trying to build a simple live wallpaper app, inspired by https://github.com/cyunrei/Video-Live-Wallpaper. One of the modifications I want to make is to not ...
1
vote
0
answers
147
views
Activity Context VS Activity VS Activity Scoped Injection in Hilt
I have some questions regarding Hilt library based on this article I have read :
When (and When Not) to Pass the Activity Context in Android
Why we should inject Context instead of activity object in ...
0
votes
1
answer
33
views
Sometimes context.startActivity(intent) not working in a class that extends WebSocketServer in Android
I have a class that extends WebSocketServer and waits for a request from the client application and if a message arrives, it should run an activity.
The code below shows how this works. Note that the ...
0
votes
1
answer
256
views
Per App language android - android 13 . Context - getString
val context = appContext
context.getString(key) is returning string in default language of system in android 12 , while it is returning string in selected language in android 13. Is there any ...
3
votes
2
answers
2k
views
Android Kotlin - requireContext() throws IllegalStateException inside Android Fragment's onViewCreated
I am dealing with IllegalStateException crashes pertaining to the usage of getString in onViewCreated; looking at the stack trace this goes back through getResources into requireContext, which throws ...
0
votes
2
answers
134
views
How to use context in a RecyclerView adapter for SharedPreferences? [duplicate]
I have a RecyclerView adapter for displaying a list of movies. I need to use the context to initialize the genrePreferences variable in my adapter. Where is the appropriate place in the adapter's ...
0
votes
0
answers
18
views
Function does not work in MainActivity, but works in TextRecognizerActivity [duplicate]
I have a recogniseText() function which does text recognition using google ML Kit, placed in TextRecognizerActivity. Initially, I received an image from gallery in MainActivity.kt, and passed it with ...
3
votes
0
answers
894
views
How to recreate/reinit/restart hilt components in Android?
I'm working on an app that allows you to change the language locally.
To make this work without having to restart the app, I'm using the ContextWrapper on the BaseActivity, where I assign the language ...
-1
votes
1
answer
103
views
What type of context should I use in this case and why?
I am using the following function in one of my activities of my app:
public static float convertDpToPixel(float dp, Context context){
return dp * ((float) context.getResources().getDisplayMetrics()...
1
vote
2
answers
7k
views
error: @Composable invocations can only happen from the context of a @Composable function
would like to start TimerView() in onClick - TimerView is a text composable
but the above mentioned error appears - both are marked composables
Composable
fun LosB(BLY: String, YArray: ArrayList<...
0
votes
1
answer
91
views
getContext() crashes my App when calling update RecyclerView function?
my app crashes all the time, when I want to access a specific fragment. The error is:
FATAL EXCEPTION: main
Process: com.akstudios.kindergarten, PID: 15680
java.lang.NullPointerException: Attempt to ...
1
vote
0
answers
520
views
Android: unit testing use case that saves file
I'm writing unit tests for a use case that basically creates a file with the contents of an InputStream.
However, with the lines:
val path = context.filesDir.path + "/issues.csv"
val fos = ...
0
votes
2
answers
38
views
How to avoid to hardcoded cast from context to activity?
I have MainActivity.kt with passing an activity context to MyObj-class:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(...
1
vote
2
answers
61
views
How can I use dialog from a common class in android
I use a static method from a common class in different activities. The method contains dialog. The dialog fires successfully from various activities. But when I declare the static dialog in the common ...
1
vote
0
answers
1k
views
How to get Native Android Activity in React Native
I've been trying to get the activity in a React Native app, but to no success.
When I try getting it from public class MainActivity extends ReactActivity I get the following error when I try using the ...
6
votes
1
answer
2k
views
Changing between Light/Dark modes doesn't update colors of running app. Theme is applied only after restarting app
Run into strange behaviour when trying to add support for dark theme in existing app.
I added values-night folder where I added new colors.xml with different hex for dark mode. Then I extended from ...
-1
votes
1
answer
334
views
why i have this error: view.findViewById<MapView>(R.id.map) must not be null
I'm trying to get mainActivity context and mapView inside my fragment, I tried to write some code but when I write this:
contextMain = activity?.baseContext!!
mapView = view.findViewById<MapView>...
-1
votes
2
answers
425
views
how to get context and mapView in fragment
I created a fragment in which through editText fields I would like to insert numbers to be used as parameters in a function created in another class (the function createPath of the NavFun class). The ...
0
votes
1
answer
623
views
Fragment in a Adapter of RecyclerView JAVA
I have a fragment Users which has 3 other fragments in it (tabs). For one tab ( called Friends2Fragment ) I made a recycler View and made an adapter for it. In each item of RecyclerView I have a ...
2
votes
0
answers
1k
views
How to access WindowManager using application context?
I have a scenario where in I have to use WindowManager with application context, I don't Activity context there.
But if I try to get WindowManager with application class, sometimes I get below ...
0
votes
2
answers
4k
views
Where to put Android Compose global variable (e.g. preferences DataStore) - Context is appropriate for the Composables only?
I am trying to introduce preferences DataStore in my Android Compose app and several tutorials suggest the use of Conext for keeping the reference to the DataStore instance. E.g. https://...
0
votes
1
answer
1k
views
Kotlin: Is this a good way to avoid memory leaks? [closed]
I was always facing this memory leak warning without paying much attention to it, but now I'm looking into how to deal with it and, as I know I shouldn't use WeakReference and that sort of "...
0
votes
0
answers
520
views
Classifier 'Context' does not have a companion object, and thus must be initialized here
Here is my code
fun Uri.getOriginalFileName(context: Context): String? {
return context.contentResolver.query(this, null, null, null, null)?.use {
val nameColumnIndex = it.getColumnIndex(...
1
vote
1
answer
960
views
Kotlin + Hilt: Injecting activity context to object class
I have an object with many screen related methods (I put only two as an example here) as follows:
object AWScreen {
private lateinit var context: Context
fun init(context: Context) {
...
67
votes
3
answers
41k
views
Android 13 (SDK 33): PackageManager.getPackageInfo(String, int) deprecated. what is the alternative?
Starting from API level 33 the getPackageInfo(String, int) method of PackageManager class is deprecated. Documentation suggests to use getPackageInfo(String, PackageInfoFlags) instead. But that ...
0
votes
1
answer
2k
views
How can I get the package name of the android in any file with in a static method
I am trying to get the package name of the app using the below code in my adapter java file. But I am getting nullpointer exception.
Fatal Exception: java.lang.NullPointerException
Attempt to invoke ...
1
vote
1
answer
616
views
Getting NULL in context while auto restart with BROADCAST RECEIVER in Android app
I am developing android application which need auto restart when restart device for that I am using broadcast receiver with action BOOT_COMPLETED.
Broadcast receiver is receiving message when I am ...
0
votes
1
answer
425
views
Android: launcher Activity is sometimes created in wrong ApplicationContext
The following code crashes in 0.01% of app launches on a few devices [see below].
public class MyApp extends Application {
private static MyApp app;
public void onCreate() {
super....
0
votes
0
answers
182
views
Flutter: should I use other variable names for 'internal' BuildContexts?
It has just recently come to my attention, that in many cases, such as when using a FutureBuilder or calling showDialog(), we have to define a builder which takes a BuildContext as an argument, and ...
0
votes
0
answers
194
views
is there any internal call for requireContext() in android
I'm using getContext() directly without using the requireContext(), but I got crash with
Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:...
1
vote
1
answer
103
views
Pass Application to singleton directly in Android
I'm a beginner to Android development.
When making a singleton in the Application Context, here is my code.
I pass the application context to the instantiation
class Blah{
companion object {
@...
0
votes
1
answer
264
views
Cannot use vibration in a Thread
I'm trying to use the vibrator service inside a Thread class but when I do so, I have an error which says "Type mismatch: inferred type is String but Context was expected"
here is my code :
...
1
vote
1
answer
1k
views
Android Kotlin: Having a global Context object for all activities (best practice)
I have a global app settings class as follows:
class AppSettings : MultiDexApplication() {
override fun onCreate() {
super.onCreate()
instance = this
resourses = ...
0
votes
0
answers
1k
views
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? in react-native android
I want to show a custom view when the app is turned off or when the app is turned on, depending on the phone state.
so I use WindowManager. but get error message
W/System.err: android.view....
0
votes
0
answers
848
views
How to provide activity or application context in Hilt to ViewModel?
Hello I have a button in recyclerview, I would like to show dialog when in one element of recyclerview the button is clicked.
I have done:
in Adapter:
class SetGoalsAdapter(
private val ...
0
votes
1
answer
712
views
Android: should we pass context to domain layer?
I am trying to use the architecture recommended by android in a project and I was wondering if it is legitimate and recommended to pass the context to the domain layer through the AndroidViewModel:
...
0
votes
0
answers
303
views
How to provide context to firebaseManager using Hilt
I would like to provide context to FirebaseManager.kt
class FirebaseManager @Inject constructor(
@ApplicationContext val context: Context,
firebaseFirestore: FirebaseFirestore,
...
2
votes
0
answers
529
views
What's "context ?: return binding.root" meaning in Android Fragment?
I am checking Sunflower sample app from Google. And I found an interesting part.
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
...
0
votes
0
answers
1k
views
How do I get the context from MainActivity for use in a different class, without passing it
I have a list of CustomClass and a function which returns this list in their own kotlin file. The function is only ever called from MainActivity but since it is not in the same file I cannot pass ...
1
vote
0
answers
512
views
How to get the context in JNI_OnLoad, when the loadLibrary() is under attachBaseContext
I have to get the context in the JNI_OnLoad. Due to some reason, I have to call the System.loadLibrary() in the attachBaseContext() but not onCreate().
I use the code in https://stackoverflow.com/a/...
1
vote
1
answer
265
views
RecyclerView: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()'
First of all, I am completefy noob to android development and I am making this project for my college where I display items in a Recycler view, each Item has a delete button and it updates the product ...
0
votes
1
answer
177
views
Android getActivity() Context Goes Stale Over Time in PopupWindow
I have an app that uses a popupWindow for user chat. It is launched from a Fragment, and the supplied context is getActivity(). I will be typing in the popupWindow's multilineEditText and, after about ...
0
votes
1
answer
2k
views
Get Current Context for Overlay Flutter
I want to display notifications that are being processed by a provider on an open gRPC stream. This is handled by notificationProvider.dart:
if (notification.type == 0) {
showOverlayNotification(...
0
votes
1
answer
1k
views
Best way to get the context of an activity in a viewmodel
I want to use this context to make a notification, but it should be called in a viewmodel that is made by hiltViewModel() function. How should I pass the context there?
0
votes
3
answers
371
views
I want to integrate ad to my app, but the problem is that the ( Type mismatch. Required: Context!, Found Fragment class)
I want to integrate ad to my app, but the problem is that the
MobileAds.initialize(this){ initStatus-> not work this method( onCreateView)
But I am use this method( onCreate:
MobileAds.initialize(...
0
votes
1
answer
91
views
Is the Application context always available?
The following is from this post:
public class MyApp extends android.app.Application {
private static MyApp instance;
public MyApp() {
instance = this;
}
public static ...