android-context

How can I call getContentResolver in android?

我是研究僧i 提交于 2019-12-04 02:10:25
I'm writing a library class to encapsulate some of my logic in my first Android app. One of the functions which I want to encapsulate is a function which queries the address book. As such, it needs a ContentResolver . I'm trying to figure out how to keep the library functions black-boxed... that is, to avoid having each Activity pass in its own context to get a ContentResolver . Problem is I cannot for the life of me figure out how to get a ContentResolver from within my library function. I can't find an import that contains getContentResolver . Googling said to use getContext to get a Context

Android Holo Light styling changes depending on chosen context

妖精的绣舞 提交于 2019-12-04 00:55:37
问题 I have been trying to find the cause of weird formatting style inconsistencies for my Views throughout my application and I think I have narrowed it down with this example. I set up two equivalent layouts of various Views s with exactly the same procedure and only varying the Context supplied in creation. In the first set, each View is created with the application's context through Activity.getApplicationContext() , whereas in the second set the View s are fed the activity's context through

How many types of context in android and what is better to use

大兔子大兔子 提交于 2019-12-03 15:48:37
问题 I just wanted to know how many ways to get the context, which method used in which situation. Which one better to use, and what is the main and key deference between them. 回答1: For Your better understands you should read android official blog. an also look at HackBod Answer. There are some references URL which help you more about the context What exactly does using the Application Context mean? Difference between Activity Context and Application Context http://android-developers.blogspot.de

Is not accessible in current context

£可爱£侵袭症+ 提交于 2019-12-03 14:53:17
问题 I have the following code public abstract class BaseAdapter<T, V extends BaseAdapter.ViewHolder> extends ArrayAdapter<T> { public BaseAdapter(Context context, int resource, Collection<T> collection) { // typical constructor logic } // some other custom defined methods public static class ViewHolder { // custom defined logic } } public class ModelAdapter extends BaseAdapter<Model, ModelAdapter.ModelViewHolder> { public ModelAdapter(Context context, int resource, Collection<Model> collection) {

Passing Activity Context to constructors to use internally - is this bad

耗尽温柔 提交于 2019-12-03 08:32:11
问题 Is it bad practice to pass the Context to a constructor and save it as a private variable for internal use? The other option is to pass the Context as a parameter to methods that need it. Which is a better option? I have a feeling that passing to the constructor might result in memory leaks accidentally. 回答1: Often, all you need is the ApplicationContext , so what you can do is pass this.getApplicationContext() instead of just this . Your app context exists for the lifetime of the app anyway,

Check and Avoid Memory Leaks in Application

帅比萌擦擦* 提交于 2019-12-03 06:04:44
问题 So, I am done with a project, now the main issue I am facing is the Memory Leakage in the application (“leak” meaning you keep a reference to an activity, thus preventing the GC from collecting it) Some of the cases I found, where the memory leakage occurs are: Context Leakage It occurs because of long lived reference to the activity context. A very good example of it i found here, private static Drawable sBackground; @Override protected void onCreate(Bundle state) { super.onCreate(state);

Is not accessible in current context

房东的猫 提交于 2019-12-03 05:41:55
I have the following code public abstract class BaseAdapter<T, V extends BaseAdapter.ViewHolder> extends ArrayAdapter<T> { public BaseAdapter(Context context, int resource, Collection<T> collection) { // typical constructor logic } // some other custom defined methods public static class ViewHolder { // custom defined logic } } public class ModelAdapter extends BaseAdapter<Model, ModelAdapter.ModelViewHolder> { public ModelAdapter(Context context, int resource, Collection<Model> collection) { super(context, resource, collection); // typical constructor logic } public static class

How many types of context in android and what is better to use

谁说胖子不能爱 提交于 2019-12-03 05:18:35
I just wanted to know how many ways to get the context, which method used in which situation. Which one better to use, and what is the main and key deference between them. Dwivedi Ji For Your better understands you should read android official blog. an also look at HackBod Answer . There are some references URL which help you more about the context What exactly does using the Application Context mean? Difference between Activity Context and Application Context http://android-developers.blogspot.de/2009/01/avoiding-memory-leaks.html Thanks Context class represents the local environment of an

Passing reference to activity to utility class android

老子叫甜甜 提交于 2019-12-03 03:22:35
I realise this question has been asked many times, but I am still unable to completely understand this concept. In my application, I am using a static utility class to keep common methods (like showing error dialogs) Here is how my static class looks like: public class GlobalMethods { //To show error messages public static final void showSimpleAlertDialog(final Activity activity, String message, final boolean shouldFinishActivity) { if (!activity.isFinishing()) { AlertDialog.Builder builder = new AlertDialog.Builder(activity, AlertDialog.THEME_HOLO_DARK); builder.setCancelable(true).setMessage

How to call Context and Intent objects inside onBindViewHolder

有些话、适合烂在心里 提交于 2019-12-02 23:30:03
问题 I want to open a new Activity within RecyclerView , but I can't create an Intent object in there. val intent1 = Intent(this,Main2Activity::class.java) startActivity(intent1) Android Studio warns about Intent not being a Context . How can I still open a new Activity inside the RecyclerView I tried also the code below,it gives "startActivity(intent)" line gives error, "type mismatch, required Context, found Intent". Plus, also "this@MainActivity" gives "unresolved reference@MainActivity" error.