RSS

Tag Archives: active

Android: get active, current or foreground Activity


In our recent Android App development, we developed many static utility functions, which needs a Context as the argument:

public static void func1(Context context, …)
public static void func2(Context context, …)
public static void func3(Context context, …)

public static void funcN(Context context, …)

This is very cumbersome. We would like to refactor these utility functions into functions without the context argument/ A natural idea to pass in the application context at the very beginning, e.g. Application.onCreate() function, but not in all cases, can we use the application context. For instance, when you create a dialog or toast window, we need to use Activity as the context. So here comes the function that works:

image

Visit this gist to get the source code.

Advertisements
 
Leave a comment

Posted by on July 13, 2016 in Android, Programming

 

Tags: , , , , , , ,

How to switch between python 2.x and python 3.x


It is known that Python2.x can coexist with Python3.x. But how do you switch the active version in use? Simple: go to edit system environment variables (shortcut key: Windows + Break), and set the path variable as shown in the snapshot:

image

If you replace the path from Python27 to Python34, for instance, then you are setting the active Python version from 2.7 to 3.4.

 

 
Leave a comment

Posted by on April 9, 2014 in Programming, Python

 

Tags: , , , ,