Log in or register to post comments

Application.quit problem with Android

February 8, 2013 - 12:45am #1

Hello,

 

I'm using the export to eclipse option in unity because I want to create a native UI. All is ok, but I have this  process:

Activity A -> Activity B ->Activity C -> ExtensionOfQualcommActivity

 

When I go back (with a custom button that says Application.quit in unity script or with other button that calls the java method finish(), is equal); goes to application C and very fast go to activity B and is a very strange behavior. I saw that when activiy c resume the application calls the oncreate method of activity b but i don't know why.

 

Thanks.

Application.quit problem with Android

July 20, 2016 - 9:14am #24

Hi sunilkm! three years later.. I found this thread and I see your code, I wonder if is java code o c#? where should I put this in my project?

Application.quit problem with Android

May 29, 2013 - 3:05am #23

HiHamasakisan

First of all thanks for providing alternative solution.  

But  there is no need of calling startActivity(ActivityC) again.

Here's code it worked perfect for me.

 
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    super.onKeyDown(keyCode, event);    
        if(keyCode == KeyEvent.KEYCODE_BACK) {
           finish();
           OnDestroy();
            return true;
        }
    return super.onKeyUp(keyCode, event);
}

Application.quit problem with Android

May 26, 2013 - 10:48pm #22

Hi, thanks for sharing this solution !

POSSIBLE FIX to Application.quit problem with Android

May 26, 2013 - 1:36pm #21

Hi. I know this is quite old and I had the same problem, but I fixed by this way... First and very important: Don't add the "Application.quit()" on the hardware back button or any other inside Unity. We are going to override this android button inside of our java activity.

On the "devisuar" structure, we have something like this:

Activity A -> Activity B -> Activity C -> ExtensionOfQualcommActivity

but when the ExtensionOfQualcommActivity is finished, it kills too the Activity C. As result, we have this:

Activity A -> Activity B

Fix:

1. On our activity C, we are going to launch the QCARActivity like this:

Intent qcar = new Intent(getApplication(),QCARActivity.class);
startActivity(qcar);
 
IMPORTANT! When you start the QCAR activity, don't kill the activity C. So, dont call "finish()", keep the Activity alive.
 
2. Inside the QCARActivity, we are going to override the back button. VERY IMPORTANT!!! OVERRIDE "ONKEYUP" AND NOT "ONKEYDOWN". If you do that, the QCARACtivity stop with a bunch of issues and kills your app.
 
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    super.onKeyDown(keyCode, event);    
        if(keyCode == KeyEvent.KEYCODE_BACK) {
            Intent activityC = new Intent(getApplication(), ActivityC.class);
            startActivity(activityC);
            finish();
            return true;
        }
    return super.onKeyUp(keyCode, event);
}
 
When you release the hardware back button, we are going to launch a new Activity C. At this point we got this stack:
 
Activity A -> Activity B ->Activity C* -> ExtensionOfQualcommActivity -> Activity C

When QCARActivity finish, inevitable going to kill the previous instance of Activity C (marked up with *), thats why we don't need to finish it at the point number 1. 

Finally,  the new Activity C becomes the top activity of the stack:

Activity A -> Activity B -> Activity C

I hope someone find this useful. I have tested on different devices and it works.

Best regards, Alex Licea.

Application.quit problem with Android

February 8, 2013 - 4:55am #20

I have to rectify my previous message; in the ImageTargets sample we have multiple levels (Unity scenes) but those are considered part of the same Android Activity (so it's probably not a good example for your case);

have you tried to do the same using a Unity project which does not use Vuforia ?

I have the impression that the problem is about Unity - Android interaction mechanisms, not really caused by Vuforia itself;

it would be good to make such test (and also perhaps look in the Unity Forum, as I would guess that other folks have faced similar issues)

 

Application.quit problem with Android

February 8, 2013 - 4:29am #19

OK, at this point, I would suggest to have a look at the ImageTargets sample in Unity; there you have multiple activities chained together as well, but that probelm does not seem to occur.

 

Application.quit problem with Android

February 8, 2013 - 4:29am #18

I  localized the problem:

 

The system always says span_exclusive_exclusive spans cannot have a zero length before close.

Application.quit problem with Android

February 8, 2013 - 4:25am #17

Ok,

 

The problem is:

When in vuforia I pulse the back button, it calls finish or application.quit (I have two button for probe). I want to simply go to previous activity (activityC). But the problem is that inmediatly after load activityC the application is kill (there are no memory issue) and again is load int the activityB sreen.

Application.quit problem with Android

February 8, 2013 - 4:22am #16

 application calls oncreate again after exit vuforia

Not sure to follow here; can you be more specific on the exact workflow ?

Application.quit problem with Android

February 8, 2013 - 4:11am #15

Overrriding the methods of application I discover that the application calls oncreate again after exit vuforia. Is that what i don't want.

Application.quit problem with Android

February 8, 2013 - 4:05am #14

Nothing, it's always the same.

 

But activityc never calls ondestroy(). I think that qcar is killing the app on purpose.

Application.quit problem with Android

February 8, 2013 - 3:37am #13

From what you describe, the problem is always with activity C (i.e. it looks like activity C is exiting in any case, when you return from Qualcomm);

have you tried replacing activity C with a very basic activity which simply launches Qualcomm activity, and which shows for instance a button "Go back to Activity B" and nothing else ?

It might be that Activity C has some problems on its own...

 

Application.quit problem with Android

February 8, 2013 - 3:21am #12

I think application.quit and finish() are killing the process, how can i override this?

Application.quit problem with Android

February 8, 2013 - 2:51am #11

Sending signal PID: 25511 SIG:9 

It's the message in my LogCat.

Application.quit problem with Android

February 8, 2013 - 2:51am #10

Ok,

the same behavior reproduces in all cases.

When actB -> actC -> actQualcom     :     go to actC and fast to actB

When actC -> actQualcom: go to actC and fast out of the app.

Thanks.

Application.quit problem with Android

February 8, 2013 - 2:32am #9

I would suggest to try and reproduce this in a simpler case; for instance, making a two-activities app (just Activity A and the Qualcomm one, then adding a third activity B in the middle, etc.); if you do it in steps, you should be able to narrow down the problem more easily.

 

 

Application.quit problem with Android

February 8, 2013 - 2:32am #8

Ok, thanks. I thought this not because it was logical, more becouse I don't understand the problem.

Application.quit problem with Android

February 8, 2013 - 2:30am #7

The non-vuforia activities are in another project that is set as library, ¿it can be a problem?

I don't think so; the fact that the other project is set as a library is perfectly ok; (if you had some problems with this, you would have run-time errors for instance, but nothing related to the Activity "life-cycle issue" that you observe in your case...)

 

Application.quit problem with Android

February 8, 2013 - 2:02am #6

It's all equal. I can't see the problem. There aren't no memory alert and there is no reason for doing that. The non-vuforia activities are in another project that is set as library, ¿it can be a problem?

Application.quit problem with Android

February 8, 2013 - 1:29am #5

I'm going to try.

But the activity c starts without problem when I go back. The problem is that activity b starts to and I don't want. In fact, when the splash screen of unity is on screen I can go back to activity c without this problem.

 

Thank you.

Application.quit problem with Android

February 8, 2013 - 1:27am #4

Ok, I see; that's strange, but it sounds like something possibly wrong in your Activity C implementation;

have you tried using startActivityForResult () function instead of startActivity() when you launch Qualcomm activity from Activity C ?

This should enforce Activity C to stay there as it needs to process the result gotten from Qualcomm activity (even if the result is just a dummy value);

maybe that could solve it.

http://developer.android.com/reference/android/app/Activity.html

 

Application.quit problem with Android

February 8, 2013 - 1:11am #3

Thank you.

The application lifecycle is a bit weird in android.

But my main problem is that when i go back to the activity c, very soon go to activity b and it isn't the expected behavior. I want to go back to activity c and let the user choose to interactuate with c or go back to b or reinitiate vuforia.

 

THanks.

Application.quit problem with Android

February 8, 2013 - 1:07am #2

Hi, I don't know the details of your Activity implementation, but from a general point of view, the Android system may decide to destroy an Activity when this is not in the foreground (which is the case for Activity B, sicne Activity C and then QualcommActivity are activated and shown on top of B);

this can happen if for example the system needs to free some resources (memory); so, if the system decides to kill (destroy) Activity B, then it is normal that the onCreate will be called when you switch back to Activity B.

Note that when destroying an Activity due to resource optimization (e.g. low on memory), Android will "remember" that such Activity was there (in a sense, it is killing the activity but keeping track that it existed so that it is "as if" the Activity was still alive.....), therefore it will still allow you to switch from Activity C to Activity B, despite the fact that B was destroyed (the only issue being that it will have to call onCreate to recreate the activity, as you observe);

this may sound trricky or weird, but that's the way Android manages activities, as also explained here:

http://developer.android.com/training/basics/activity-lifecycle/recreating.html

However, if the system destroys the activity due to system constraints (rather than normal app behavior), then although the actual Activity instance is gone, the system remembers that it existed such that if the user navigates back to it, the system creates a new instance of the activity using a set of saved data that describes the state of the activity when it was destroyed.

I hope this answers your question.

Log in or register to post comments