Terminate android program

Hi there. I have used the exit() function to exit the program but it only closes the window. is there a command which will terminate the program completely? thanks.

@gonadgranny===
normally that is “finish()”

hi thanks but that doesnt register in the IDE…

@gonadgranny===

…or, in a fragment::
this.getActivity().finish()

thanks but this seems to do the same as exit(). it just closes the window but leaves the program running…

@gonadgranny===
i said “normally” because result depends of your code && your app: are you using services, broadcast and so on. Put some snippet and show at what point you want your app to finish()

its a fairly hefty program now, im using these libraries if it helps:

import android.content.Intent;
import android.os.Bundle;
import ketai.net.bluetooth.;
import ketai.ui.
;
import ketai.net.;
import oscP5.
;
import android.app.Activity;
import android.content.Context;
import android.os.Vibrator;
import android.view.MotionEvent;

this how i have used the code:

  //EXIT BUTTON CODE
  if (exit_btn.pressed()) {
    //exit();
    this.getActivity().finish();
  }

@gonadgranny ===

  • what happens when you hit your button???

  • as i cannot see the code it s difficult to help, but from the import i guess that you are perhaps using a service (blueTooth)

yes i am using bluetooth. the button is purely there to quit the program.

@gonadgranny===
ok and you probably (or ketati) is using it as a background service…
but what happens exactly when you hit your button ???

other than execute the code you gave me i can only think of providing you with the button.pressed() method which is executed in order to know it has been pressed:
boolean pressed() { //// if (mouseOver()) { pressed = !pressed; vibrate(); return true; } else { return false; } }

it just checks whther the button has been pressed and also uses vibrate() to make the device vobrate

@gonadgranny===

  • the code below works, try it
  • if finish does not work with your code that is probably because you have a service which is running, kill it before calling finish()
  • anyway, calling finish or this kind of things is against android principles and there are very few cases where you have to do that

 void setup(){
   size(800,1000);
   background(255,0,255);
 }
 
 
 void draw(){
   
   textSize(36);
   text("finish", 50,height/2);
   
 }
 
 
void mouseReleased(){
   this.getActivity().finish();
 }

thanks i will try this when i get the chance. why is it against android principles? i just want to quit the program, it seems strange that it is so difficult…?

@gonadgranny====

with android a) the user must always choose what he wants and in this case it s very easy to leave your app (back button, home button…) b) the os is always able to kill an app for memory reasons eg c) normally it does not, your app is running in the background, waiting for restart (“resume()”);

i see, when it is in the background is it in a kind of sleep mode?

@gonadgranny ===
yes, exactly && that s why apps can restart very quickly

ok well maybe i’ll just forget about quitting then.thanks very much for the information. one other thing is that as the complexity of my program grew, i noticed that the program did not become responsive for some time when i ‘woke it up’ again. more so than actually opening the program from scratch. could you have any guesses at what this may be? the bluetooth services perhaps?

@gonadgranny====
yes, “normally” you must kill services, i say normally because in some cases (notifications…) you can want that they stay alive…

I’m not sure if you are familiar with ketai but if you are would this bt.disconnectDevice(connectedDeviceName); suffice to kill the service?

@gonadgranny===

i never use ketai; yet looking at this code i am not sure: it can disconnect a device without killing the service itself; for that android has the stopSelf() method or stopService()(depending where it’s called.