Android Application Class
Application wide object.
You can actually create an “Application” class that can be used to essentially create Application wide settings.
Just create a new class and extend Application, then set any class members and appropriate getter/setter methods and you can access them throughout your application.
You then need to update your manifest as follows:
<application android:icon="@drawable/logo"
android:label="@string/app_name"
android:name=".application.CustomApplication">
Then in any activity you can access it as follows:
CustomApplication app = ((CustomApplication)getApplication());
Get Application context from phonegap cordova plugin
- Register your activity in the AndroidManifest file
- In your plugin you should have the code like this, notice no “callback.success()” is called
- Run the action in ui thread and not background thread.
if (action.equals(“myaction”)) { cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { Context context = cordova.getActivity() .getApplicationContext(); Intent intent = new Intent(context, MyNewActivityGap.class); cordova.getActivity().startActivity(intent); } });return true; }
<code> Context context = cordova.getActivity().getApplicationContext(); Intent intent = new Intent(context,Next_Activity.class);
cordova.startActivityForResult(this, intent,0); </code>