Hi everyone,
Is there anyway to start new intent in Android without cause game crashed?? I want my game open an URL, so I tried to start another Activity with WebView. But it doesn’t work
This is what I tried
- First, I add a function to start new Activity in my current Activity
public static void openURL(String url)
{
Intent intent = new Intent(m_sInstance.getApplicationContext(), WebViewActivity.class);
m_sInstance.startActivity(intent);
}
- Second, I add some native code that I can open an URL in C++:
jni_wrapper.h
#include <jni.h>
>
#include <android/log.h>
>
#define LOG_TAG “JNI”
#define LOGD (…) *android_log_print
#define LOGI (…)*android_log_print(ANDROID_LOG_INFO,LOG_TAG,VA_ARGS)
>
#define JNI_FUNCTION(function) Java_my_android_loadweb_ ## function
>
#ifndef JNI_WRAPPER
#defineJNI_WRAPPER
#ifdef cplusplus
extern “C” {
#endif
>
extern JNIEnv mEnv;
extern jclass mClassGame;
>
static jmethodID mMethodOpenURL;
>
void nativeOpenURL;
#ifdef cplusplus
}
#endif
jni_wrapper.c
#include <stdio.h>
>
#include “jni_wrapper.h”
>
#ifdefcplusplus
extern “C” {
#endif
>
JNIEnvmEnv;
jclass mClassGame;
>
JNIEXPORT void JNICALL JNI_FUNCTION
{
LOGI (“JNI nativeInit”);
>
mEnv = env;
mClassGame = ->NewGlobalRef;
>
mMethodOpenURL = ->GetStaticMethodID V");
}
>
void nativeOpenURL
{
// JNIEnv *mEnv = NVThreadGetCurrentJNIEnv;
jstring string = ->NewStringUTF;
->CallStaticVoidMethod;
// ->DeleteLocalRef;
}
>
#ifdefcplusplus
}
#endif
- Finally, I call nativeOpenURL(…) in HelloWorldScene.cpp
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
nativeOpenURL(“http://www.google.com”);
// CCDirector::sharedDirector()->end();
>
// #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// exit(0);
// #endif
}
=> But it’s crashed, I tried to get stack trace, and here is the result
nativeOpenURL
:0
*ZN10HelloWorld17menuCloseCallbackEPN7cocos2d8CCObjectE
:0
*ZN7cocos2d10CCMenuItem8activateEv
:0
_ZN7cocos2d6CCMenu12ccTouchEndedEPNS_7CCTouchEPNS_7CCEventE
>:0
>*ZN7cocos2d17CCTouchDispatcher7touchesEPNS_5CCSetEPNS_7CCEventEj
>:0
>*ZN7cocos2d17CCTouchDispatcher12touchesEndedEPNS_5CCSetEPNS_7CCEventE
>:0
ZN7cocos2d17CCEGLViewProtocol16handleTouchesEndEiPiPfS2
:0
Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesEnd
>:0
I attached all of them below. Here are some info:
Cocos version: cocos2d-2.0-rc2-x-2.0.1
Android SDK: r15
Android NDK: r8b
Android OS: 2.3.6
Phone: LG E400
Thanks a lot
AndroidLoadWeb.zip (629.7 KB)