I have just started learning about Unity so this may seem like a stupid question.
I have made a small minigame that renders a character when the device camera sees a specific image. My problem is that I want to show some kind of menu before the unity activity is triggered.
For example in my code, I changed my launcher activity to be my main activity and when the start button in pressed then I would like that the unity activity would be triggered (and my device camera will open). Unfortunately it's not working (my app crashes when I press the button) and my logcat doesn't show anything.
This is my manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="imp.diana.samurai"
android:installLocation="preferExternal"
android:theme="#android:style/Theme.NoTitleBar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="23" />
<uses-feature android:name="android.hardware.camera" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen.multitouch"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen.multitouch.distinct"
android:required="false" />
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:debuggable="false"
android:icon="#drawable/app_icon"
android:isGame="true"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name=".UnityPlayerNativeActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="fullSensor" >
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
<meta-data
android:name="unityplayer.ForwardNativeEventsToDalvik"
android:value="false" />
</activity>
<activity
android:name="com.unity3d.player.VideoPlayer"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<!--
To support devices using the TI S3D library for stereo mode we must
add the following library.
Devices that require this are: ODG X6
-->
<uses-library
android:name="com.ti.s3d"
android:required="false" />
<!-- To support the ODG R7 in stereo mode we must add the following library. -->
<uses-library
android:name="com.osterhoutgroup.api.ext"
android:required="false" />
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest> <!-- android:installLocation="preferExternal" -->
Main Activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button start = (Button) findViewById(R.id.button);
start.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, UnityPlayer.class));
}
});
}
UnityPlayerActivity
public class UnityPlayerActivity extends Activity
{
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
// Setup activity layout
#Override protected void onCreate (Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.RGBX_8888); // <--- This makes xperia play happy
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings().getBoolean("hide_status_bar", true))
{
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
}
// Quit Unity
#Override protected void onDestroy ()
{
mUnityPlayer.quit();
super.onDestroy();
}
// Pause Unity
#Override protected void onPause()
{
super.onPause();
mUnityPlayer.pause();
}
// Resume Unity
#Override protected void onResume()
{
super.onResume();
mUnityPlayer.resume();
}
// This ensures the layout will be correct.
#Override public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
// Notify Unity of the focus change.
#Override public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
// For some reason the multiple keyevent type is not supported by the ndk.
// Force event injection by overriding dispatchKeyEvent().
#Override public boolean dispatchKeyEvent(KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
return mUnityPlayer.injectEvent(event);
return super.dispatchKeyEvent(event);
}
// Pass any events not handled by (unfocused) views straight to UnityPlayer
#Override public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); }
#Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); }
#Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
/*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); }
}
Any idea? Any help would be greatly appreciated!
You probably haven't listed UnityPlayerActivity in the AndroidManifest.xml file using the tags <activity></activity> e.g.
<activity
android:name=".UnityPlayerActivity"
android:label="#string/app_name"
...
>
</activity>
Related
Since Google warned us to provide support to 64-bit architecture, I am migrating my existing Unity Project from version Unity 5.6.6f to Unity 2018.4.1f
Upon running my project app crashes with log,
2019-06-02 20:08:27.869 14987-14987/com.example.myapplication:unityplayer E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication:unityplayer, PID: 14987
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.UnityActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2747)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6375)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.content.res.Resources.getText(Resources.java:347)
at android.content.res.MiuiResources.getText(MiuiResources.java:97)
at android.content.res.Resources.getString(Resources.java:393)
at com.unity3d.player.UnityPlayer.a(Unknown Source)
at com.unity3d.player.UnityPlayer.<init>(Unknown Source)
at com.example.myapplication.UnityActivity.onCreate(UnityActivity.java:52)
at android.app.Activity.performCreate(Activity.java:6845)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
STEPS I HAVE DONE FROM MY END
I have created a new project in Unity 2018.4.1f and changed the scripting back-end configuration to IL2CPP to support 64-bit architecture.
Please see my configuration below.
I have changed the package name in Unity to that my Android app package name and exported the build.
After exporting, I have pasted the Library folder, Asset folder and JniLibs folder contents (which I got from exported Unity Android project) to my Android project respective folders.
My UnityActivity file in Android Studio Project,
package com.example.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;
import android.widget.FrameLayout;
import com.unity3d.player.UnityPlayer;
public class UnityActivity extends Activity {
protected static UnityPlayer mUnityPlayer; // don't change the name of UnityPlayer.currentActivity variable; referenced from native code
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.RGBX_8888); // <--- UnityPlayer.currentActivity makes xperia play happy
mUnityPlayer = new UnityPlayer(this);
setContentView(mUnityPlayer);
FrameLayout cameraLayout = findViewById(R.id.unity_player_layout);
cameraLayout.addView(mUnityPlayer.getView());
mUnityPlayer.requestFocus();
}
#Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
}
// Quit Unity
#Override
protected void onDestroy() {
if (mUnityPlayer != null) {
mUnityPlayer.quit();
}
super.onDestroy();
}
// Pause Unity
#Override
protected void onPause() {
super.onPause();
System.out.println("OnPause called");
mUnityPlayer.pause();
}
// Resume Unity
#Override
protected void onResume() {
super.onResume();
System.out.println("OnResume called");
mUnityPlayer.resume();
}
#Override
protected void onStop() {
super.onStop();
System.out.println("Onstop called");
}
// Low Memory Unity
#Override
public void onLowMemory() {
super.onLowMemory();
mUnityPlayer.lowMemory();
}
// Trim Memory Unity
#Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
if (level == TRIM_MEMORY_RUNNING_CRITICAL) {
mUnityPlayer.lowMemory();
}
}
// UnityPlayer.currentActivity ensures the layout will be correct.
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
// Notify Unity of the focus change.
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
// For some reason the multiple keyevent type is not supported by the ndk.
// Force event injection by overriding dispatchKeyEvent().
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
return mUnityPlayer.injectEvent(event);
return super.dispatchKeyEvent(event);
}
// Pass any events not handled by (unfocused) views straight to UnityPlayer
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return mUnityPlayer.injectEvent(event);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
return mUnityPlayer.injectEvent(event);
}
/*API12*/
public boolean onGenericMotionEvent(MotionEvent event) {
return mUnityPlayer.injectEvent(event);
}
#Override
protected void onUserLeaveHint() {
super.onUserLeaveHint();
}
#Override
public void onBackPressed() {
super.onBackPressed();
UnityPlayer.currentActivity.runOnUiThread(new Runnable() {
#Override
public void run() {
mUnityPlayer.quit();
}
});
}
}
Corresponding XML file,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="#+id/unity_player_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
My AndroidManifest file looks like
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front.autofocus"
android:required="false" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen.multitouch"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen.multitouch.distinct"
android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<!-- Allows access to the flashlight -->
<permission
android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal"
android:required="false" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true">
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<activity
android:name=".UnityActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection"
android:label="#string/app_name"
android:launchMode="singleTask"
android:process=":unityplayer"
android:screenOrientation="landscape">
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
<meta-data
android:name="unityplayer.ForwardNativeEventsToDalvik"
android:value="true" />
</activity>
<!--
To support devices using the TI S3D library for stereo mode we must
add the following library.
Devices that require this are: ODG X6
-->
<uses-library
android:name="com.ti.s3d"
android:required="false" /> <!-- To support the ODG R7 in stereo mode we must add the following library. -->
<uses-library
android:name="com.osterhoutgroup.api.ext"
android:required="false" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Since, I am a native developer and knows little about Unity, any help to sort out this issue will be really helpful!
I have to add the below line to strings.xml file to get rid of the error!
<string name="game_view_content_description">Game view</string>
The steps that explains the problem I faced are below;
1. I start the android application.
2. I put it on backgorund by pressing home button.
3. I turn the screen off.
4. I turn the screen on after some seconds.
5. My application suddenly becomes foreground. I realised that the application is forced to start again and the application class that I used is created again and then the start page of my application (this is login page) is shown although what page is opened before the step 2.
What I have tried so far is below;
I put configChanges and screenOrientation in all the activiy tags in my Androidmanifest.xml (I tried to put them one by one and both together also.)
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name="com.myproject.Activity"
android:screenOrientation="nosensor"/>
I also tried to use screenOrientation="portrait" but didn't work.
My problem is related with the How do I disable orientation change on Android?, Prevent Android activity from being recreated on turning screen off and like others, but I could not find the solution of my problem yet.
Can you please help?
Edit 1: ********************************
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myproject"
android:versionCode="1"
android:versionName="1.0"
xmlns:tools="http://schemas.android.com/tools" >
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<!-- Permission to use NFC -->
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc.hce"
android:required="true" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<permission android:name="com.myproject.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.myproject.permission.C2D_MESSAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<!--
Add this permission to check which network access properties (e.g.
active type: 3G/WiFi).
-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Add this permission to access WLAN MAC address. -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Add this permission to access HW ID. -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<application
android:name="com.myproject.hce.MyApplication"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/MyAppTheme"
tools:replace="android:icon,android:theme"
>
<!-- Splash Activity -->
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name=".Splash"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
android:windowSoftInputMode="stateHidden"
android:screenOrientation="nosensor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Login Activity -->
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name="com.myproject.LoginView"
android:screenOrientation="nosensor"
android:windowSoftInputMode="adjustResize" >
</activity>
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name="com.myproject.MainView"
android:screenOrientation="nosensor" >
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/fb_app_id" />
<meta-data
android:name="com.crashlytics.ApiKey"
android:value="12h3g21h4v32hv43hv4" />
<service
android:name="com.myproject.pushnotifications.GCMIntentService"
android:enabled="true" >
</service>
<service
android:name="com.myproject.hce.McbpHceService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE" >
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="#xml/apduservice" />
</service>
<receiver
android:name="com.myproject.pushnotifications.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RETRY" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
<service
android:name="com.myproject.hce.MyService"
android:exported="true"
android:enabled="true"
android:stopWithTask="false"/>
</application>
</manifest>
Application class
public class MyApplication extends Application {
private static MyApplication MyApplication;
private MyActivityLifeCycleCallbacks MyActivityLifeCycleCallbacks;
public static MyApplication getMyApplication() {
return MyApplication;
}
#Override
public void onCreate() { //coko1
MyLog.i(UtilConstants.LOG_TAG_HCE, "MyApplication " + "onCreate ...");
if (MyApplication == null)
MyApplication = this;
else
return;
MyLog.i(UtilConstants.LOG_TAG_HCE, "MyApplication " + "super.onCreate() ...");
super.onCreate();
registerActivityLifecycleCallbacks(new MyLifecycleHandler());
setMyActivityLifeCycleCallbacks(new MyActivityLifeCycleCallbacks());
registerActivityLifecycleCallbacks(getMyActivityLifeCycleCallbacks());
}
public MyActivityLifeCycleCallbacks getMyActivityLifeCycleCallbacks() {
return MyActivityLifeCycleCallbacks;
}
public void setMyActivityLifeCycleCallbacks(
MyActivityLifeCycleCallbacks MyActivityLifeCycleCallbacks) {
this.MyActivityLifeCycleCallbacks = MyActivityLifeCycleCallbacks;
}
}
Edit 2:****************
Splash.java
public class Splash extends Activity {
public static Context context;
public static final String LOG_TAG = "Splash ";
#Override
public void onCreate(Bundle bundle)
{
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onCreate...");
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); // catch unexpected error
super.onCreate(bundle);
context = this;
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "MainView starts...");
Intent mainIntent = new Intent(Splash.this, MainView.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
#Override
protected void onResume() {
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onResume ...");
super.onResume();
}
}
MainView.class
public class MainView extends Activity {
Context context;
String LOG_TAG = "MainView ";
#Override
public void onCreate(Bundle savedInstanceState)
{
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onCreate ...");
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
context = this;
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "LoginView starts...");
Intent loginIntent = new Intent(Splash.this, LoginView.class);
Splash.this.startActivity(loginIntent);
Splash.this.finish();
}
#Override
protected void onResume() {
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onResume ...");
super.onResume();
}
#Override
protected void onStart() {
super.onStart();
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onStart ...");
};
#Override
protected void onPause() {
super.onPause();
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onPause ...");
};
#Override
protected void onDestroy() {
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onDestroy ...");
super.onDestroy();
};
}
Edit 3:****************
I use fragments, maybe this will be the reason, but I am not sure.
The problem is due to a library I used. It works in background and makes the application restarts.
I suspend it when the application goes to background and resume it when it comes foregorund. That is it, the problem is solved.
Thanks you anyway.
APP is in pause state. I am changing the language(localization) of the phone afterwards when I select the app from recent history(pause state to resume state). The following lifecycle methods are calling in following order
onDestroy
onCreate
onStart
onResume
onPause
onStop
onDestroy
but APP is not opening(view is not appearing).
Here I have given the source code of activity and android manifest file.
Any help is appreciated?
public class CordovaExample extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
Log.i("onCreate Called","onCreate Called");
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.i("OnStart Called","OnStart Called");
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.i("onResume Called","onResume Called");
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.i("onPause Called","onPause Called "+Locale.getDefault().getLanguage());
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.i("onStop Called","onStop Called");
}
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.i("onDestroy Called","onDestroy Called");
}
}
manifestfile:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.apache.cordova.rest"
android:hardwareAccelerated="true"
android:versionCode="1"
android:versionName="1.0"
android:windowSoftInputMode="adjustPan" >
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:hardwareAccelerated="true"
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:name="org.apache.cordova.rest.CordovaRestClient"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
</manifest>
Open the following Java File in cordova library project
framework/src/org/apache/cordova/CordovaWebView.java
Replace the following line of code
if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url))
to
if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)&& !url.equals("about:blank"))
It is working fine now
We are developing an Android app.
We are going to wake up Lock-mode, when our App receives a GCM message in Sleep mode.
program works well in Android 4.1 (Jelly-Bean, API 16).
but it does not work in Android 4.3 (Jelly-Bean, API 19).
What is the problem? Please let us know!!!
We programmed as follows:
follow is class files :
public class GCMIntentService extends GCMBaseIntentService {
#Override
protected void onMessage(Context context, Intent intent) {
//...some code omitted...
Intent newIntent;
newIntent = new Intent(context, SomeActivity.class);
newIntent.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(newIntent);
}
}
public class SomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
//...some code omitted...
WakeLockManager.setWakeUp(this);
//...some code omitted...
super.onCreate(savedInstanceState);
}
#Override
protected void onStart() {
//...some code omitted...
super.onStart();
}
#Override
protected void onResume() {
//...some code omitted...
super.onStart();
}
#Override
protected void onPause() {
//...some code omitted...
super.onPause();
}
protected void onStop() {
//...some code omitted...
super.onStop();
};
#Override
protected void onDestroy() {
//...some code omitted...
super.onDestroy();
}
}
public class WakeLockManager {
public static void setWakeUp(Context context) {
Window wnd = ((Activity)context).getWindow();
wnd.addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
);
}
}
follow is manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<permission
android:name="com.mycompany.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.mycompany.myapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<application
android:name="com.mycompany.myapp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme" >
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.mycompany.myapp" />
</intent-filter>
</receiver>
<service android:name="com.mycompany.myapp.GCMIntentService" />
<activity
android:name="com.mycompany.myapp.activities.SomeActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:theme="#style/NoActionBar"
android:screenOrientation="landscape" >
</activity>
<activity
android:name="com.appkorea.newdriver.activities.MainActivity"
android:configChanges="orientation"
android:label="#string/app_name"
android:theme="#style/AuthTheme"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- ...some code omitted... -->
</application>
</manifest>
in case of API 19, when staring SomeActivity, the onCreate() call-back function is called over 1 times.
I guess several reason as follow.
1. SomeActivity's screenOrientation value is landscape.
So for rotating activity, the onCreate() call-back function is called once.
2. To unlock the lockScreen, the android system show the lock screen,
and rotate the screen into portrait.
because current lock-screen's screenOrientation value is portrait.
At this time, SomeActivity is already created.
so the onCreate call-back function is called once.
3. After unlocking, To show the SomeActivity, the onCreate() is called once.
but now device screenOrientation is portrait,
and SomeActivity's screenOrientation is landscape.
so the onCreate() is called again.
As above that is written, onCreate() is called over 1 times. Unfortunately I don't have a android phone 4.3 now. So I can not show the logcat. Later soon, I will upload the logcat screen capture. Really Thanks to read.
I am Using android Google map API-2 for my application. When clicking map view it shows only a screen with zoom button.
my AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.burusoth.advertise"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.burusoth.advertise.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.burusoth.advertise.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.CALL_PHONE" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.burusoth.advertise.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.burusoth.advertise.View_Advertisements"
android:label="#string/title_activity_view__advertisements" >
</activity>
<activity
android:name="com.burusoth.advertise.Gadget_view"
android:label="#string/title_activity_gadget_view"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="com.burusoth.advertise.Activity_post_advertisements"
android:label="#string/title_activity_activity_post_advertisements" >
</activity>
<activity
android:name="com.burusoth.advertise.Post_Advertisement"
android:label="#string/title_activity_post__advertisement" >
</activity>
<activity
android:name="com.burusoth.advertise.Popup"
android:label="#string/title_activity_popup" >
</activity>
<activity
android:name="com.burusoth.advertise.Google_Map"
android:label="#string/title_activity_google__map" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAKCvpyR3v4YStDJDoibNgoblkdch0F254" />
</application>
my activity xml file
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Google_Map" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
my Activity .java Activity file for calling map
public class Google_Map extends Activity {
private GoogleMap googleMap=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google__map);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_google__map, menu);
return true;
}
private void initilizeMap() {
if (googleMap == null) {
googleMap =((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
Here with I would like to share one example which run under Google Map API v2.
You can go through that steps or else you can download full example from below link.
This is working example. Please test this in real device.
Google Maps API v2 using Android
Please provide your comment if you have any question.
You need to put API_KEY in android manifest
Get from :
Google Map API_KEY