gpg:: AndroidSupport
#include <android_support.h>
Functions which enable pre- Android 4.0 support.
Summary
Android Lifecycle Callbacks
For apps which target Android 2.3 or 3.x devices (API Version prior to 14), Play Game Services has no way to automatically receive Activity lifecycle callbacks. In these cases, Play Game Services relies on the owning Activity to notify it of lifecycle events. Any Activity which owns a GameServices object should call the AndroidSupport::* functions from within their own lifecycle callback functions. The arguments in these functions match those provided by Android, so no additional processing is necessary.
For apps which target android 4.0+ (API Version greater than or equal to 14), most of these function calls are unnecessary. For such apps only the OnActivityResult function must be called.
Example code for a pre- Android 4.0 game using a Java Activity
In your Java Activity, please add the following. You may need to merge this code with your existing lifecycle functions.
import android.app.Activity; import android.content.Intent; public class YourActivity extends Activity { protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); nativeOnActivityCreated(this, savedInstanceState); } protected void onDestroy(){ super.onDestroy(); nativeOnActivityDestroyed(this); } protected void onPause(){ super.onPause(); nativeOnActivityPaused(this); } protected void onResume(){ super.onResume(); nativeOnActivityResumed(this); } protected void onStart(){ super.onStart(); nativeOnActivityStarted(this); } protected void onStop(){ super.onStop(); nativeOnActivityStopped(this); } protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); nativeOnActivitySaveInstanceState(this, outState); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); nativeOnActivityResult(this, requestCode, resultCode, data); } // Implemented in C++. private static native void nativeOnActivityCreated( Activity activity, Bundle savedInstanceState); private static native void nativeOnActivityDestroyed(Activity activity); private static native void nativeOnActivityPaused(Activity activity); private static native void nativeOnActivityResumed(Activity activity); private static native void nativeOnActivitySaveInstanceState( Activity activity, Bundle outState); private static native void nativeOnActivityStarted(Activity activity); private static native void nativeOnActivityStopped(Activity activity); private static native void nativeOnActivityResult( Activity activity, int requestCode, int resultCode, Intent data); }
void Java_com_example_yourapp_YourActivity_nativeOnActivityCreated( JNIEnv* env, jobject thiz, jobject activity, jobject saved_instance_state) { gpg::AndroidSupport::OnActivityCreated(env, activity, saved_instance_state); } void Java_com_example_yourapp_YourActivity_nativeOnActivityDestroyed( JNIEnv* env, jobject thiz, jobject activity) { gpg::AndroidSupport::OnActivityDestroyed(env, activity); } void Java_com_example_yourapp_YourActivity_nativeOnActivityPaused( JNIEnv* env, jobject thiz, jobject activity) { gpg::AndroidSupport::OnActivityPaused(env, activity); } void Java_com_example_yourapp_YourActivity_nativeOnActivityResumed( JNIEnv* env, jobject thiz, jobject activity) { gpg::AndroidSupport::OnActivityResumed(env, activity); } void Java_com_example_yourapp_YourActivity_nativeOnActivitySaveInstanceState( JNIEnv* env, jobject thiz, jobject activity, jobject out_state) { gpg::AndroidSupport::OnActivitySaveInstanceState(env, activity, out_state); } void Java_com_example_yourapp_YourActivity_nativeOnActivityStarted( JNIEnv* env, jobject thiz, jobject activity) { gpg::AndroidSupport::OnActivityStarted(env, activity); } void Java_com_example_yourapp_YourActivity_nativeOnActivityStopped( JNIEnv* env, jobject thiz, jobject activity) { gpg::AndroidSupport::OnActivityStopped(env, activity); } void Java_com_example_yourapp_YourActivity_nativeOnActivityResult( JNIEnv* env, jobject thiz, jobject activity, jint request_code, jint result_code, jobject data) { gpg::AndroidSupport::OnActivityResult( env, activity, request_code, result_code, data); }
Example code for an Android 4.0+ game using a Java Activity
In your Java Activity, please add the following. You may need to merge this code with your existing lifecycle functions.
public class YourActivity extends Activity { protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); nativeOnActivityResult(this, requestCode, resultCode, data); } // Implemented in C++. private static native void nativeOnActivityResult( Activity activity, int requestCode, int resultCode, Intent data); }
void Java_com_example_yourapp_YourActivity_nativeOnActivityResult( JNIEnv* env, jobject thiz, jobject activity, jint request_code, jint result_code, jobject data) { gpg::AndroidSupport::OnActivityResult( env, activity, request_code, result_code, data); }
Public static functions |
|
---|---|
OnActivityCreated(JNIEnv *env, jobject activity, jobject saved_instance_state)
|
void
Should be called to forward data from your Java activity's onActivityCreated.
|
OnActivityDestroyed(JNIEnv *env, jobject activity)
|
void
Should be called to forward data from your Java activity's OnActivityDestroyed.
|
OnActivityPaused(JNIEnv *env, jobject activity)
|
void
Should be called to forward data from your Java activity's OnActivityPaused.
|
OnActivityResult(JNIEnv *env, jobject activity, jint request_code, jint result_code, jobject result)
|
void
Should be called to forward data from your Java activity's OnActivityResult.
|
OnActivityResumed(JNIEnv *env, jobject activity)
|
void
Should be called to forward data from your Java activity's OnActivityResumed.
|
OnActivitySaveInstanceState(JNIEnv *env, jobject activity, jobject out_state)
|
void
Should be called to forward data from your Java activity's OnActivitySaveInstanceState.
|
OnActivityStarted(JNIEnv *env, jobject activity)
|
void
Should be called to forward data from your Java activity's OnActivityStarted.
|
OnActivityStopped(JNIEnv *env, jobject activity)
|
void
Should be called to forward data from your Java activity's OnActivityStopped.
|
Public static functions
OnActivityCreated
void gpg::AndroidSupport::OnActivityCreated( JNIEnv *env, jobject activity, jobject saved_instance_state )
Should be called to forward data from your Java activity's onActivityCreated.
Only necessary for Android 2.3.x support.
OnActivityDestroyed
void gpg::AndroidSupport::OnActivityDestroyed( JNIEnv *env, jobject activity )
Should be called to forward data from your Java activity's OnActivityDestroyed.
Only necessary for Android 2.3.x support.
OnActivityPaused
void gpg::AndroidSupport::OnActivityPaused( JNIEnv *env, jobject activity )
Should be called to forward data from your Java activity's OnActivityPaused.
Only necessary for Android 2.3.x support.
OnActivityResult
void gpg::AndroidSupport::OnActivityResult( JNIEnv *env, jobject activity, jint request_code, jint result_code, jobject result )
Should be called to forward data from your Java activity's OnActivityResult.
OnActivityResumed
void gpg::AndroidSupport::OnActivityResumed( JNIEnv *env, jobject activity )
Should be called to forward data from your Java activity's OnActivityResumed.
Only necessary for Android 2.3.x support.
OnActivitySaveInstanceState
void gpg::AndroidSupport::OnActivitySaveInstanceState( JNIEnv *env, jobject activity, jobject out_state )
Should be called to forward data from your Java activity's OnActivitySaveInstanceState.
Only necessary for Android 2.3.x support.
OnActivityStarted
void gpg::AndroidSupport::OnActivityStarted( JNIEnv *env, jobject activity )
Should be called to forward data from your Java activity's OnActivityStarted.
Only necessary for Android 2.3.x support.
OnActivityStopped
void gpg::AndroidSupport::OnActivityStopped( JNIEnv *env, jobject activity )
Should be called to forward data from your Java activity's OnActivityStopped.
Only necessary for Android 2.3.x support.