Issue
I would like know how to send a command to an activity which has started from inside another function. More precisely I want to send a pause intent to com.google.vr:sdk... the view is started like this:
class VRPlayer {
private void playVideo(int sourceType, Context context) {
Intent intent = new Intent(context, VrVideoActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
private void pauseVideo(Context context, JSONArray args) {
VrVideoActivity.class.toggleVideoPlay(); <------------- NOT WORKING ¯\_(-_- )_/‾
}
}
once the activity has started there should be a way to execute other function, ex: toggleVideoPlay()
which are inside the VrVideoAcitivity
from the but I can't get the right way to do it... If you want to try it you can find the Android project here: https://github.com/StarStep/android-help-vr
Solution
VrVideoActivity vrVideoActivity = new VrVideoActivity();
vrVideoActivity.toggleVideoPlay();
a simple way -> (new VrVideoActivity).toggleVideoPlay();
another way -> set the toggleVideoPlay();
to static as following
public static void toggleVideoPlay()
{
//Your Code
}
and call it VrVideoActivity.toggleVideoPlay();
Answered By - Raed Ghazal
Answer Checked By - Marie Seifert (JavaFixing Admin)