Reputation: 45
Can some one help me get the reference to the current activity from the Myapp that extends Application. I'm trying to implement a simple shake feature that uses the sesmic library. Once the shake is detected I need to have the reference to the current activity so that I can save a screen shot of the current view. I need to access the current activity something like
enter public class MyApp extends Application {
public onSomeTriggerCallThisFunction() {
Activity currentActivity = getCurrentActivity();
}}
Can someone help me with getCurrentActivity()
Upvotes: 0
Views: 1063
Reputation: 197
you should set currentActivity when you call each activity in onCreate or onResume activity method like that. G is my Application class and currentActivity is my static field in G class
@Override
protected void onResume() {
super.onResume();
G.currentActivity = this;
}
Upvotes: 2
Reputation: 5176
For API level 14 :
They added new public function
public void registerActivityLifecycleCallbacks (Application.ActivityLifecycleCallbacks callback)
Implementing them in your application class can give access to current activity.
To read about it's Documentation...
An Example to get started with...
Upvotes: 2