Cocos2d-js: How to exit an application in Android and Ios? - android

I like to know how to exit an app in a good way in Android and Ios?
In the helloworld app of cocos2d-js this code is unfortunately omitted:
var closeItem = cc.MenuItemImage.create(
res.CloseNormal_png,
res.CloseSelected_png,
function () {
cc.log("Menu is clicked!");
}, this);
What can be there instead of
cc.log("Menu is clicked!");
?

For Android, you should call CCDirector::sharedDirector()->end(); to end the app. For Apple though, you could call exit(0) but its not really recommended to exit apps and will appear sort of like a crash. Do you need a close button? Most apps don't tend to have them and just keep running until the system or the user kills them.

Related

How to make a flutter app run in background?

I am developing an app which uses an embedded system connected to through Bluetooth to an embedded device and I want the app to run a function when the device sends a signal.
The issue is that I cannot keep the app open all the time and thus need the app to keep running in the background and keep listening for the signal send by the embedded device so that it can run the function I want.
I have seen the following questions :
How to run flutter app in background continually?
How can I make my flutter app run in background without stopping?
How to create a service in Flutter to make an app to run always in background?
and many more and so far nothing seems to work.
I have written this code for now :
Future<void> _run_app_in_background() async {
final config = FlutterBackgroundAndroidConfig(
notificationTitle: 'MEDICA',
notificationText:
'MEDICA is running in the background',
notificationIcon: AndroidResource(name: 'background_icon'),
notificationImportance: AndroidNotificationImportance.Default,
);
var hasPermissions = await FlutterBackground.hasPermissions;
hasPermissions = await FlutterBackground.initialize(androidConfig: config);
final backgroundExecution =
await FlutterBackground.enableBackgroundExecution();
}
but it seems to be doing nothing and the same with other packages.
So how can I make my app run in background to keep listening for the Bluetooth data sent by device.
Edit:I want this to run on both Android and iOS and if possible maybe someone can suggest me another framework apart from Flutter (in comments maybe) and I can search the internet for the same.
#HrishabhNayal Hello bro Try this way!
https://medium.com/dlt-labs-publication/flutter-run-code-in-the-background-461b4d6c635b

How do I retrieve extras from the launched app with cordova-plugin-app-launcher

I am trying to pass a parameter to another application.
I am using cordova-plugin-app-launcher to launch the other application.
Both applications are wrapped by Cordova and only are available on Android.
In this moment I don't have access to the code of the second application which is launched, so I can't test a solution right now.
I saw the GitHub documentation talks about extras, and for the launch part would be something like this:
window.plugins.launcher.launch({uri:'fb://profile', extras: [{"name":"param1", "value":"VALUE1", "dataType":"String"}]}, successCallback, errorCallback);
I would like to know how to retrieve this extra on the launched app (maybe on the App.controller.js?).
EDIT
I think this can be handled by this other plugin
document.addEventListener('deviceReady', function(){
window.plugins.intent.getCordovaIntent(function (Intent) {
console.log(Intent);
}, function () {
console.log('Error');
});
}
Can someone please confirm is this is the way to do this or this is a good/bad practice? I would like to know if you have any suggestion to perform this logic I would really appreciate it. Thanks.
Cordova apps cannot capture startup parameters out of the box.
Someone has tried and has a fix for iOS I believe but I haven't seen anything for Android.
See this issue
You might also want to look into https://www.npmjs.com/package/cordova-plugin-intent

Event handler for close/force stop an ionic app

I am developing an ionic app. I am wondering if there is any event handler for this condition when the app is being stop/close in follow ways:
1) Settings -> Application -> Application Name -> Force stop
2) Swipe to close app.
I would expect something like this. But the best i could found is to cater for app exiting via $ionicPlatform.registerBackButtonAction which does not include the above two scenario.
Also, I am not sure whether this can be done in native platform as well. Please advise on this.
angular.module('app').run(function($ionicPlatform) {
$ionicPlatform.onAppStopOrForceClose(function() {
// Any function here
});
});
ionic.Platform.exitApp(); // stops the app
window.close();
see: http://ionicframework.com/docs/api/utility/ionic.Platform/
if you try in ios: you can't exit an IOS App, Apple do not allow apps to exit programmatically

navigator.app.exitapp() not working in android device

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", backButtonEvent, false);
}
function backButtonEvent() {
var currentUrl=window.location.hash;
if(currentUrl=='#/homePage' || currentUrl=='#/'){
navigator.app.exitApp();
}
else{
history.go(-1);
navigator.app.backhistory();
}
}
Iam using ionic framework and phone gap.. here when i click device backbutton from home page its just minimizing that app not exiting. How can i exit my app??
In case you mean by minimizing that app that the application goes to the background (is not the active application but it is still in the list of running applications). In case that is what you mean, please notice that this is the normal behavior in Android and many Mobile OS.
Terminating (exiting if you prefer) the application is not under the control of the application developer. It is completely managed by the OS (Android in this case). So, what you have is the normal behavior for apps under Mobile OS.
Instead of terminating the application as you would do under old OS (Linux, Windows and alike), you have to manage the lifecycle of the application: pause, resume, ...
Install plugin https://github.com/ZhichengChen/cordova-plugin-android-home.
Implement 2 handlers for plugins.
Use the bellow code to exit the application.
exitApp:function() {
app.exitApp();
}

How to test vibration function in android?

I am writing a simple Phonegap application for Android. This program will send notification to notification bar and make the phone vibrate periodically.
I use navigator.notification.vibrate(time_period) to achieve the target. According to this article, both beep and vibration are not supported by android emulator. Hence, I was expecting that there could be entry indicating failure of it in the Catlog, but there is no such entry. The question is how to make sure that a vibration event has happened or failed (without deploying to a device).
AppHarbor looks like one of the ways to debug Phonegap application remotely. I wonder if there is other local ways to test Phonegap application as an HTML5 website in a Chrome browser (navigator.notification call is a standard call)? If yes, then it is probably possible to somehow parse the browser's console automatically to find out if the vibration event has happened.
Can you hide the vibrate() call behind an abstraction which you can replace depending on which platform you are using?
For example
var vibrateFunc = function(time_period) {
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
console.log('vibrating for ' + time_period)
} else {
navigator.notification.vibrate(time_period)
}
}
and then have your app code call vibrateFunc() whenever it wants to vibrate.

Categories

Resources