android-context Questions

2

Solved

My users can select files via ACTION_OPEN_DOCUMENT val launcher = rememberLauncherForActivityResult( contract = ActivityResultContracts.OpenDocument(), onResult = onResult ) After which I use ta...

2

I have a class that creates (or opens) a file to write some data to it. This class receives a Context in the constructor, saves it in an instance field, and then uses it to call the context.openFil...
Burrill asked 28/3, 2014 at 13:45

21

Solved

I am trying to implement MVVM pattern in my android app. I have read that ViewModels should contain no android specific code (to make testing easier), however I need to use context for various thin...
Beutler asked 21/7, 2018 at 0:29

3

Solved

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 fun...
Fictitious asked 17/8, 2022 at 11:55

3

I'm developing an app with React Native for both iOS and Android, and I am trying to prevent device-specific scaling of the display in the app. For text/font size scaling, putting the following co...

8

Solved

I have an activity which creates an object instance of my class: file MyActivity.java: public class MyActivity extends Activity { TextView myView = (TextView)findViewById(R.id.myView); ... Poin...
Ula asked 17/5, 2011 at 12:47

18

Solved

I've found the R.string pretty awesome for keeping hardcoded strings out of my code, and I'd like to keep using it in a utility class that works with models in my application to generate output. Fo...
Arbuthnot asked 23/11, 2010 at 6:23

1

companion object { @Volatile private lateinit var instance: ExampleDatabase fun getInstance(context: Context): ExampleDatabase { synchronized(this) { if(!::instance.isInitialized) { instance...
Fullblooded asked 11/3, 2020 at 8:20

16

Solved

I am aware of the availability of Context.getApplicationContext() and View.getContext(), through which I can actually call Context.getPackageName() to retrieve the package name of an application. ...
Zephan asked 5/7, 2011 at 23:0

5

Solved

Getting the context inside onClick(View view), the callback for a button's onClickListener(), is easy: view.getContext() But I can't figure out how to get the context inside onClick(DialogInterf...
Flagitious asked 27/3, 2011 at 3:53

4

Solved

I'm using Context to access system level services like WifiManager and BluetoothManager. How to mock this getApplicationContext() using Mockito?
Larva asked 3/12, 2015 at 10:43

32

Solved

In Android programming, what exactly is a Context class and what is it used for? I read about it on the developer site, but I am unable to understand it clearly.
Linsk asked 26/8, 2010 at 6:12

7

Solved

I am trying ProgressDialog. But I am confused. 1. pd=ProgressDialog.show(MainActivity.this, "", "Fething data"); when I do use (MainActivity.this) then it is ok. But 2. pd=Prog...
Monck asked 9/4, 2014 at 15:3

3

Solved

Is it possible to pass arguments to an Android Handler?? I have two pieces of code. new Thread(){ public void run(){ for(;;){ uiCallback.sendEmptyMessage(0); Thread.sleep(2000); //sleep for 2 ...
Neubauer asked 28/3, 2011 at 17:13

28

Solved

I have implemented a ListView in my Android application. I bind to this ListView using a custom subclass of the ArrayAdapter class. Inside the overridden ArrayAdapter.getView(...) method, I assign ...
Tina asked 12/10, 2010 at 20:0

4

I took inspiration from google's sample on how to test your SharedPreferences code here by creating a SharedPreferencesHelper class: https://github.com/googlesamples/android-https://github.com/goo...
Petrography asked 10/7, 2016 at 20:40

12

Solved

Starting with a recent new version of ADT, I've noticed this new attribute on the layout XML files, for example: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:...

7

Solved

I allways get this java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference error while ...

3

Solved

Is there an Intent that goes directly to the "Enable USB Debugging" toggle or a way to request it to be enabled? ---Situation Explanation--- We have an application we use for testing on many phon...
Semaphore asked 2/5, 2019 at 23:20

6

Solved

I have a Listview with a ContextMenu, but when I setIcon for ContextMenu look like it doesn't work public void onCreateContextMenu(ContextMenu menu , View v, ContextMenuInfo menuInfo){ super.o...
Alanson asked 7/8, 2009 at 15:49

10

Solved

In an Android app, is there anything wrong with the following approach: public class MyApp extends android.app.Application { private static MyApp instance; public MyApp() { instance = this; ...
Cutout asked 12/6, 2009 at 14:54

9

Solved

I don't really get the idea behind how this whole thing works really, so if I have some class A that need the context of a class B which extends Activity, how do i get that context? I'm searching ...
Foreland asked 7/9, 2012 at 15:12

1

Solved

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...
Jobber asked 16/9, 2022 at 9:58

7

I have several classes in my application. Some are Activities, Services and Pure java classes. I know i can display a Toast message within an Activity, but I'd like to display a Toast from a pure j...
Industrialism asked 23/12, 2013 at 11:17

4

Solved

In my application i want show message when fragment has show. I used viewPager and BottomNavBar for show 4 fragments! I want when click on BottomNavBar items show fragment and i want when visibilit...
Northrop asked 28/3, 2019 at 16:4

© 2022 - 2025 — McMap. All rights reserved.