[System] Need a way to kill itself from app

RESOLVED WORKSFORME

Status

--
major
RESOLVED WORKSFORME
5 years ago
5 years ago

People

(Reporter: leo.bugzilla.gaia, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

5 years ago
Description: We have a test app that runs tests and wants to kill itself when it is done. However, the app can't call WindowManager.kill(this), because it is not a system app.

Is there any way to kill itself from an app?

Thanks

Updated

5 years ago
Flags: needinfo?(alive)

Comment 1

5 years ago
Is this accessible from an app?

AppWindow.prototype.kill from system/js/window.js
Please attach your code.
I write some code in template app today:

window.addEventListener('visibilitychange', function() {
  if (document.hidden)
    window.close();
});

And this works for me.
(In reply to hanj.kim25 from comment #1)
> Is this accessible from an app?
> 
> AppWindow.prototype.kill from system/js/window.js

No.
Flags: needinfo?(alive)

Comment 4

5 years ago
(In reply to Alive Kuo [:alive] from comment #2)

Actually, we were using window.close();. Somehow in some cases, the app remains in the cardview. (I'm looking for the repro steps, or a better way to kill itself.) Swiping up doesn't even kill the app when this happens.

I'm not sure about the repro steps but I have those two apps calling window.close().

'A' app calls window.close() when home key is pressed.
'B' app calls window.close() when its exit button is clicked.

1. Launch an A app.
2. From A app, it launches a B app through MozActivity.
3. Press exit button on B app, and it calls window.close();
4. Go to cardview and return to A app. 
5. Press home key, then A app calls window.close();

When I repeat the steps above and maybe some random things in between, the A app becomes in the state above. It never goes away from cardview..


A app does this.

        try {
		window.close();
	} catch (err) {
		console.log('exiting app Exception::' + err.message);
	}

B app does the same

        window.close();
(In reply to hanj.kim25 from comment #4)
> (In reply to Alive Kuo [:alive] from comment #2)
> 
> Actually, we were using window.close();. Somehow in some cases, the app
> remains in the cardview. (I'm looking for the repro steps, or a better way
> to kill itself.) Swiping up doesn't even kill the app when this happens.
> 
> I'm not sure about the repro steps but I have those two apps calling
> window.close().
> 
> 'A' app calls window.close() when home key is pressed.
> 'B' app calls window.close() when its exit button is clicked.
> 
> 1. Launch an A app.
> 2. From A app, it launches a B app through MozActivity.

What kind of activity? Window or Inline?

> 3. Press exit button on B app, and it calls window.close();
> 4. Go to cardview and return to A app. 

This step tells me it's window position activity.

> 5. Press home key, then A app calls window.close();

Could you use visibilitychange event listener, please?

> 
> When I repeat the steps above and maybe some random things in between, the A
> app becomes in the state above. It never goes away from cardview..
> 
> 
> A app does this.
> 
>         try {
> 		window.close();
> 	} catch (err) {
> 		console.log('exiting app Exception::' + err.message);
> 	}

Do you really see err?



Could you give me the full source code? This would save my time to rewrite a new test.

Comment 6

5 years ago
(In reply to Alive Kuo [:alive] from comment #5)

Sorry Alive, this is not my codes.. I'm not sure if I can. That's why.. 


One thing I just found out is, the following steps reproduces the issue right away.

1. Launch an A app.
2. Press home key many times, fast.

then the app goes to the weird state, described earlier. I am suspecting that this is because window.close(); is called more than once, fast..

I have just put a boolean to make sure the A app is calling window.close() only once. But the issue still exists when home key is pressed many times.. Do you see any problem with home key press event, too many times, too fast, when app gets killed?

Comment 7

5 years ago
(In reply to Alive Kuo [:alive] from comment #5)

Ops, I just saw your comment, to use "visibilitychange event listener".
Sure, let me try. 
Thanks!
This is not a general case: Press home screen and the app die at the same time(WindowManager.kill is called)

I cannot tell what happens.

Recently there's a bug resolving the quickly pressing home button event: bug 896393.

And I suggest to look into https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/window_manager.js#L1438
if you want to debug by yourself.
(Reporter)

Comment 9

5 years ago
Using "visibilitychange event listener" should resolve the issue. Thanks again!
Closing.
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.