android-context

set a new context to WebView

这一生的挚爱 提交于 2019-12-08 05:17:33
问题 Is there any way to change the context of WebView? I mean, when I extend the WebView class I call the super constructor with a context (in my example an activity). Later on, this activity is no longer exists and we move to other activity. The problem is the WebView is still alive and has a reference to this context. I can't create my WebView any time because the initialisation is long. I tried to call the super class with getApplicationContext() but I found that this also problematic for

Android - using Singleton to access hold application settings, and Context

ぃ、小莉子 提交于 2019-12-08 03:26:04
问题 I need to access settings from various activities in my Android app. Rather than messing around with SharedPreferences in various activities I want to create a Singleton class, and grab all the settings at once using SharedPreferences in the Singleton. I also want a method in the Singleton to save settings where required, again using SharedPreferences. The trouble with this is that I need an Activity context to use SharedPreferences. Could I pass this into the Singleton.. I've read about

Memory-leak free Singleton with context

蹲街弑〆低调 提交于 2019-12-08 02:27:56
问题 I am trying to implement the following singleton pattern: SingletonClass.getInstance(context).callMethod() While there are a variety of tutorials that explain how to make singletons in Kotlin, none of them address the fact that holding a context in a static field will cause memory leaks in Android. How do I create the above pattern without creating a memory leak? Update: Here is my implementation of CommonsWare's solution #2. I used Koin. Singleton class: class NetworkUtils(val context:

Having trouble creating a subclass of application to share data with multiple Activities

ぐ巨炮叔叔 提交于 2019-12-07 21:24:39
问题 I just finished a couple of activities in my game and now I was going to start to wire them both up to use real game data, instead of the test data I was using just to make sure each piece worked. Since multiple Activities will need access to this game data, I started researching the best way to pass this data to my Activities. I know about using putExtra with intents, but my GameData class has quite a bit of data and not just simple key value pairs. Besides quite a few basic data types, it

Android - using Singleton to access hold application settings, and Context

那年仲夏 提交于 2019-12-07 16:05:41
I need to access settings from various activities in my Android app. Rather than messing around with SharedPreferences in various activities I want to create a Singleton class, and grab all the settings at once using SharedPreferences in the Singleton. I also want a method in the Singleton to save settings where required, again using SharedPreferences. The trouble with this is that I need an Activity context to use SharedPreferences. Could I pass this into the Singleton.. I've read about memory leaks and am wary of doing this. Or am I completely barking up the wrong tree and is there a better

Android Activity Refreshing On Rotation

孤街醉人 提交于 2019-12-07 14:07:39
问题 I'm an experienced .NET dev, but this is my first Android app and it's driving me nuts! It's a countdown timer which works fine, but when you rotate the screen it reinitialised the activity which zeroed and stopped the count down. This is what I tried; I got rid of the CountDownTimer object and instead created a class internal to the activity which extended AsyncTask so it ran on a separate thread... No change. I figured being an internal class it's being reinitialised with the activity. Here

getContext().getSystemService error

守給你的承諾、 提交于 2019-12-07 07:29:12
问题 So I'm just trying to currently inflate a view in my getView function and getContext() for some reason is saying it's undefined.. package com.MTSUAndroid; import com.MTSUAndroid.Alarm_Settings.EfficientAdapter1.ViewHolder; import android.app.Activity; import android.app.AlertDialog; import android.app.ListActivity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup

How to get Context when you call a method in a different class?

女生的网名这么多〃 提交于 2019-12-07 07:27:07
问题 So basically, I have a method that requires a Context in order to perform several tasks. public void openDatePicker() { Context c; } I want to know, how to define a context of the method caller so I don't have to insert it as a parameter each time I call the method. 回答1: Lets have an basic understanding of Context . Context allows access to application-specific resources and classes , as well as calls for application-level operations such as launching activities , broadcasting and receiving

Android: android.database.Cursor.moveToFirst()' on a null object reference

孤街浪徒 提交于 2019-12-06 16:26:02
问题 I'm working about photo application and i want to implement cirlcle cropper in my project, but i have a problem about my fragment and cropper class. When i'm selected picture and press crop button and after turning fragment i'm giving this error: 06-04 02:09:34.595 21914-21914/com.stamplessapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.stamplessapp, PID: 21914 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=131094, result=-1, data=Intent { dat=file

Android getWritableDatabase() throws a NullPointerException

淺唱寂寞╮ 提交于 2019-12-06 15:57:59
问题 I am having trouble with my call to getWritableDatabase(). It is returning a NullPointerException. The thing that is strangest is that this error only began occurring after I commented out a couple lines of code in my android manifest. Now the project is back to where it was (I un-commented those sections and it still throws a NullPointerException). So I checked my context and tried this.getBaseContext() and this.getApplicationContext(). Using getApplicationContext() puts this out to logcat: