Log in or register to post comments

back button unwanted application close

March 5, 2013 - 4:41am #1

Hi,

we are using unity for our AR app. In Android when we have in AR content something like send text button and user hits it we pass to native code request to open sendign text activity. Here is a native code we call from Unity

 

 public void sendSMS(final String number, final String text){
    	Log.d("NativeWrapper", "sendSMS called, number:"+number);
    	
    	
	    	UnityPlayer.currentActivity.runOnUiThread(new Runnable() {
	         	public void run() {
	         		
				    	Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse( "sms:" + number ));
				    	intent.putExtra( "sms_body", text );
				    	UnityPlayer.currentActivity.startActivityForResult(intent, 1);;
	         	
	         	}
	    	});
    	
    	
    }

The issue we have is that if you cancel sendign text in Messaging activity by pressign back button ONCE only all is fine and the Unity app is shown and continue where it ended.

However if you cancel text message by pressing back button and then again press back button while the unity activity is not yet restored, then the app exits.

This issue shows up on all devices we tested here. We do handle key down for ESC key in unity code ourselves, so when in unity activity pressing back does not close the app, but it seems like when there is no unity activity fully active yet, there is somewhere default back handling which does close the app as there is nothing else in activity history stack.

We tried to override public void onBackPressed() and public boolean onKeyDown() in ExtendedPlayerActivity which extends QCARPlayerProxyActivity. We start this activity as main application activity. But these methods are not triggered. Is QCARPlayerProxyActivity starting another activity which is active at the time back is pressed? is there a way to override that activity onBackPressed() to handle the event in such situations?

The issue I described is happening quite often because for instance on Tablets going back from send Email or send text activities take lieke 1 or 2 seconds and user tends to press back again thinking he did not hit it properly as switching back to unity activity is not immediate and has its delay.

Thanks for help.

S.

back button unwanted application close

March 6, 2014 - 12:49pm #11

Hi

Thanks for your time bro. I got that worked now. I found another way to get unity scripts calls in java and that by using android plugins. For the steps to create an android plugin check this link:

https://developer.vuforia.com/forum/faq/unity-android-plugins

Cheers!

back button unwanted application close

March 6, 2014 - 5:13am #10

Hi, it seems to be ok. Our project is a bit more complicated by t I cannot see why this would not work.

Just to double check have you got unity-classes.jar copeid in /libs folder in your eclipse project? and does it show in Android Dependencies ?

This has changed slightly in unity4.3, I had to upgrade our project as well to reflect this change. 

back button unwanted application close

March 5, 2014 - 6:52am #9

I tried with com.qualcomm.QCARUnityPlayer.QCARPlayerNativeActivity but didn't work as well.

I attached the manifest and java file have a look on them. Maybe I missed something! I don't know.

Thanks.

AttachmentSize
Package icon Unity.zip1.43 KB

back button unwanted application close

March 5, 2014 - 6:24am #8

Hi, checked our code and I can see there only check for android version as 2.2 and below do not support native activity so extending it won't work for these versions. If you are on 2.3 and above it should be safe.

I do not see a reason why unityplayer can't be seen just by extending the nativeactivity.

What's in your manifest?

if you chnage your manifest to start again com.qualcomm.QCARUnityPlayer.QCARPlayerNativeActivity as main activity does it work then?

Alternative try to attach your manifest and class whcih extends native activity so I can have a look.

S. 

back button unwanted application close

March 5, 2014 - 5:58am #7

Hi Stan

I got this error:

Could not find class 'com.unity3d.player.UnityPlayer', referenced from method com.qualcomm.QCARUnityPlayer.QCARPlayerNativeActivity.onCreate

back button unwanted application close

March 5, 2014 - 5:39am #6

Hi,

what error are you getting in logcat when the app crashes?

S.

back button unwanted application close

March 5, 2014 - 5:03am #5

Hi

I have the same problem and tried to extend the nativeactivity but now I the app is crashes once I run it. I followed the instructions in the link your provided and tested the app after that and it crashed. If you or anybody here can help with this I'll be very thankful.

Cheers!

Ahmed

back button unwanted application close

March 11, 2013 - 11:12pm #4

Great to hear.

back button unwanted application close

March 11, 2013 - 2:56pm #3

HI,

Thnaks for tips. RTFM approach has helped me to sort this ;o)

In case anyone would be interested I had to extend nativeactivity and put the key press handler overrides there as I was extending proxyactivity and that one is only used to decide which player activity to start and then it is destroyed so no key handlers there anymore...

here's the link where thigs are explained

https://developer.vuforia.com/forum/faq/unity-how-can-i-extend-unitys-android-activity

S.

back button unwanted application close

March 6, 2013 - 12:50pm #2

Hi, not sure what the problem could be, but this sounds like an Android issue; have you tried searching in Android specific forums ?

The thread below discusses a similar issue (you may want to have a look):

http://stackoverflow.com/questions/3558385/android-onbackpressed-not-working

 

Log in or register to post comments