android-context

How do I view Android application specific cache?

百般思念 提交于 2019-11-29 23:07:45
Is there any way to dynamically view the application specific cache in Android? I'm saving images to the cache (/data/data/my_app_package/cache) and I'm 99% sure they're saving there, but not sure how long they're staying around. When I look in the cache using the DDMS File Explorer within Eclipse, it's always empty. I've also tried examining the appropriate cache dir in ADB and again it's always empty. Any suggestions? Unless ADB is running as root (as it would on an emulator) you cannot generally view anything under /data unless an application which owns it has made it world readable.

How to use Calligraphy with multi-language support Oreo

你说的曾经没有我的故事 提交于 2019-11-29 21:18:41
问题 I'm developing an app that need to support multiple languages and if the language is RTL I have to apply a custom font. For the requirement I have created my Class that extends Application . Everything was perfect till I got Oreo version device (Before I have Marshmellow enabled device). In Oreo if we want to change the language we have to create a custom ContextWrapper class, here problem come in. To use Calligraphy we need to Override the attachBaseContext method. And To change language we

Android AsyncTask context behavior

*爱你&永不变心* 提交于 2019-11-29 20:55:20
I've been working with AsyncTasks in Android and I am dealing with an issue. Take a simple example, an Activity with one AsyncTask. The task on the background does not do anything spectacular, it just sleeps for 8 seconds. At the end of the AsyncTask in the onPostExecute() method I am just setting a button visibility status to View.VISIBLE, only to verify my results. Now, this works great until the user decides to change his phones orientation while the AsyncTask is working (within the 8 second sleep window). I understand the Android activity life cycle and I know the activity gets destroyed

Android: BitmapFactory.decodeResource returning null

*爱你&永不变心* 提交于 2019-11-29 17:45:55
问题 I can't seem to figure this out. I have 2 java classes with different characteristics, each calling BitmapFactory.decodeResource to get the same image resource, one returns the bitmap while the other returns null. Both classes are in the same package. Here is the class that works, it calls BitmapFactory.decodeResource which returns the bitmap. I've only included relevant code. package advoworks.test; import android.content.Context; import android.graphics.Bitmap; import android.graphics

Extending Application

一世执手 提交于 2019-11-29 17:26:15
I'd like to extend Application in my Android app. I've done this such that I've created an extended Application object called MyApplication and added it to the manifest. I'd now like to add some getters and setters to hold some information. It looks like I'll need to pass the application Context to any classes which do not contain a Context. For example, say I create a class called MyObject (in its own java file): public class MyObject { public void doStuff() { // do stuff } } How might I access MyApplication from doStuff()? It looks like I'll need to pass the application Context to MyObject.

android - changing Activity UI from application class

让人想犯罪 __ 提交于 2019-11-29 15:32:06
I extended the Application class in order to create singleton-like object in android. in this object I have all the HTTP work with my server, and all the other activities can access it and call methods to GET, POST etc. Code: public class HttpManagerInstance extends Application { private HttpClient httpClient; private HttpGet get; @Override public void onCreate() { httpClient = new DefaultHttpClient(); get = new HttpGet("http://10.100.102.9:8000/users/"); super.onCreate(); } public Void getUsers() throws Exception { new executeRequest().execute(get); return null; } private class executeRequest

How to get Context through hooking in android

感情迁移 提交于 2019-11-29 15:24:12
The background is : I'm using xposed framework to hook a third party app. When I hook method XXX, xposed gave me "ClassNotFound" error. I checked and found the method XXX is in a dex file and would be loaded by DexClassLoader on the run. To hook the method XXX, I need to change the default ClassLoader in xposed to DexClassLoader . To get a DexClassLoader instance, I need a Context instance of the third party app. Here comes the question: how to get the context instance? I searched stackoverflow and found someone said you can hook the method in Activity or Receiver to retrieve their context.

How to call method from another class without passing context?

旧巷老猫 提交于 2019-11-29 12:24:40
I am currently trying to call a method from a utility class that will reference a new cursor created for this utility method. Unfortunately, my new class will not let me create the cursor without context. I have tried numerous ways of passing context from the calling activity, but get null pointer exceptions in most cases. Here is the portion of my code: findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Tools.pickRandomItem(); } }); and in the Tools Class: public static void pickRandomItem() { Cursor cur = getContentResolver().query

Can't cast to Application with getApplication method

烈酒焚心 提交于 2019-11-29 11:58:36
I have class App which contain context of my Application . But when I compiled I got an error in other class in this line: App app = (App) getApplication(); Class App : import android.app.Application; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.media.MediaPlayer; import android.support.v4.app.NotificationCompat; import android.util.Log; import com.example.Radio_KPI.R; import com.example.Radio_KPI.Utils.Const; public class App extends Application { private

Passing Activity or Context to other instance

二次信任 提交于 2019-11-29 10:27:53
Can you please tell me whats the best practice to pass activity or context to other instance(;) But..., What is better to pass? Activity or Context Is good idea to have the Activity as Global (public static Activity activity) here is my code. What would you change? (based on good android practices) Passing an Activity into another object that does not specifically require the Activity object is usually a bad idea. Activity extends Context so it works to satisfy a method that requires Context . In your case, you can get the Context from the View that is passed into the method. However, if you