Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
NickolasGomesMoraes
Posts: 19
Registered: ‎07-18-2012
My Device: Playbook
My Carrier: None
Accepted Solution

Closing an APP via webworks

Hello!

Few months ago i asked the same question here, unfortunatelly by lack of time i just answered that my problem was solved.

Now i need that again, but the problem isn't solved.

This is the question: How do i close an app via webworks?

The code bellow don't work.

Thanks.

<!DOCTYPE html>
<head>
<meta name="viewport" content="height=600,width=1024,user-scalable=no,target-densitydpi=device-dpi,initial-scale=1.0" />
<script type="text/javascript" src="local:///chrome/webworks.js"></script>
<script src="bbui.js" type="text/javascript" charset="utf-8"></script>
<script>
function closeapp()
{
blackberry.app.exit()
}
</script>
</head>
<body>
<button onclick="closeapp()">Close</button>
</body>
</html>
Please use plain text.
BlackBerry Development Advisor (Retired)
erikjohnzon
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: Closing an APP via webworks

That code i definitely correct IMO. This should be working. What is the observed behaviour? Nothing? What about web inspector?

 

What about the minimize function? Does that not work as well?

@erikjohnzon
erjohnson@blackberry.com
Please use plain text.
BlackBerry Development Advisor
bryanhiggins
Posts: 201
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Closing an APP via webworks

Do you have the blackberry.app feature added to config.xml?

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Please use plain text.
Contributor
NickolasGomesMoraes
Posts: 19
Registered: ‎07-18-2012
My Device: Playbook
My Carrier: None

Re: Closing an APP via webworks

Nothing happens, i just press the button and nothing is call'd.

Web inspector dont find any abormal behavior.

Also i do have the blackberry.app in the config.xml.

 

 

Nick.

Please use plain text.
BlackBerry Development Advisor
chadtatro
Posts: 619
Registered: ‎10-01-2009
My Device: Z10
My Carrier: Bell

Re: Closing an APP via webworks

Can you add some debugging, an alert perhaps, before the blackberry.app.exit method is called?  At least we can see if it's actually calling the close function in the first place.

 

You can even add a try/catch to it to capture any exceptions that may be occurring.

 

function closeapp() {
  alert('in closeapp function');
  try {
    blackberry.app.exit();
  } catch(e) {
      alert('error: ' + e);
  }
}

 

Also, pasting your config.xml in here might be a good idea as well.

Chad Tetreault | App Development Consultant | BlackBerry Developer Relations | developer.blackberry.com | @chadtatro
Please use plain text.
Trusted Contributor
lathajagan
Posts: 118
Registered: ‎03-06-2013
My Device: Blackberry Z10
My Carrier: Airtel

Re: Closing an APP via webworks

as suggested by bryanhiggins, please try pasting your config.xml here, it will be definitely the problem with feature ids or permission element, nothing more than that
--------
- If a post contains the solution to the problem, please click "Accept as Solution"
- If a post contains helpful content, please give it a "Thumbs Up"

developer.blackberry.com
@BlackBerryDev
Please use plain text.
Contributor
NickolasGomesMoraes
Posts: 19
Registered: ‎07-18-2012
My Device: Playbook
My Carrier: None

Re: Closing an APP via webworks

Hello!

Updated the code with the recommendations above.

The following error ocurred in the APP:

 


error: TypeError: 'undefined' is not a function


 

Here's the full code with the config.xml included.

 

<!DOCTYPE html>
<head>
<meta name="viewport" content="height=600,width=1024,user-scalable=no,target-densitydpi=device-dpi,initial-scale=1.0" />
<script type="text/javascript" src="local:///chrome/webworks.js"></script>
<script>
function closeapp() {
  alert('in closeapp function');
  try {
    blackberry.app.exit();
  } catch(e) {
      alert('error: ' + e);
  }
}
</script>
</head>
<body>
<button onclick="closeapp()">Close</button>
</body>
</html>

 

<?xml version="1.0" encoding="utf-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:rim="http://www.blackberry.com/ns/widgets"
        version="2.0.0.0">
 
  <author>Nickolas Gomes Moraes</author>
 
  <name>Sample application</name>
 
  <description>
    A sample application to demonstrate some features.
  </description>
 
  <rim:orientation mode="auto"/>
  
  <rim:permissions>
  </rim:permissions>
 
  <icon src="icons/example.png"/>
 
  <content src="index.html"/>
 
  <feature id="blackberry.ui.dialog"/>
  <feature id="blackberry.app.event" required="true" version="1.0.0.0"/>

</widget>

 

Thanks!

Please use plain text.
BlackBerry Development Advisor
chadtatro
Posts: 619
Registered: ‎10-01-2009
My Device: Z10
My Carrier: Bell

Re: Closing an APP via webworks

You should be using blackberry.app for the feature, not blackberry.app.event (in config.xml)

 

here's my code which works

 

CONFIG.XML

<?xml version="1.0" encoding="utf-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:rim="http://www.blackberry.com/ns/widgets"
        version="1.0.0"
        id="sample">
    <name>Localytics Sample</name>
    <content src="local:///index.html" />
    <author rim:copyright="2012"
            href="http://www.blackberry.com/"
            email = "@chadtatro">Chad Tetreault</author>
    <description></description>
    <license href="http://www.apache.org/licenses/LICENSE-2.0">
    </license>
    <access uri="*" subdomains="true" />
    <feature id="blackberry.app" />
</widget>

 

INDEX.HTML

 

<!DOCTYPE html>
<html>
    <head>
        <!-- framework -->
        <script src="local:///chrome/webworks.js" type="text/javascript">
        </script>
        <!-- initialization -->
        <script type="text/javascript">
            // webworks ready listener
            document.addEventListener("webworksready", function() {
                console.log('WebWorks has initialized');
            });

            // close the app
            function closeApp() {
                blackberry.app.exit();
            }
        </script>
    </head>
    <body>
        <button onclick="closeApp();" style="width: 100%; height: 200px;">
            CLOSE APP
        </button>
    </body>
</html>

 

Chad Tetreault | App Development Consultant | BlackBerry Developer Relations | developer.blackberry.com | @chadtatro
Please use plain text.
Contributor
NickolasGomesMoraes
Posts: 19
Registered: ‎07-18-2012
My Device: Playbook
My Carrier: None

Re: Closing an APP via webworks

Yep, that was the problem.

Shame on me.

Thanks for the help guys!

Please use plain text.