# Terminate android program

**URL:** https://discourse.processing.org/t/terminate-android-program/5114
**Category:** Processing for Android
**Created:** [November 2, 2018, 10:55am UTC](https://discourse.processing.org/t/terminate-android-program/5114 "2018-11-02T10:55:12Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 2, 2018, 10:55am UTC](https://discourse.processing.org/t/terminate-android-program/5114/1 "2018-11-02T10:55:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 2, 2018, 11:13am UTC](https://discourse.processing.org/t/terminate-android-program/5114/2 "2018-11-02T11:13:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 2, 2018, 11:38am UTC](https://discourse.processing.org/t/terminate-android-program/5114/3 "2018-11-02T11:38:09Z")

</div>

> [@akenaton](#):
>
> normally that is “finish()”

hi thanks but that doesnt register in the IDE…

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 2, 2018, 1:52pm UTC](https://discourse.processing.org/t/terminate-android-program/5114/4 "2018-11-02T13:52:37Z")

</div>

@gonadgranny===

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

---

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 2, 2018, 2:03pm UTC](https://discourse.processing.org/t/terminate-android-program/5114/5 "2018-11-02T14:03:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 2, 2018, 2:06pm UTC](https://discourse.processing.org/t/terminate-android-program/5114/6 "2018-11-02T14:06:10Z")

</div>

@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()

---

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 2, 2018, 2:08pm UTC](https://discourse.processing.org/t/terminate-android-program/5114/7 "2018-11-02T14:08:41Z")

</div>

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](http://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:

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

```

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 2, 2018, 2:44pm UTC](https://discourse.processing.org/t/terminate-android-program/5114/8 "2018-11-02T14:44:32Z")

</div>

@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)

---

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 2, 2018, 2:47pm UTC](https://discourse.processing.org/t/terminate-android-program/5114/9 "2018-11-02T14:47:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 2, 2018, 3:07pm UTC](https://discourse.processing.org/t/terminate-android-program/5114/10 "2018-11-02T15:07:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 2, 2018, 3:31pm UTC](https://discourse.processing.org/t/terminate-android-program/5114/11 "2018-11-02T15:31:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 3, 2018, 8:17am UTC](https://discourse.processing.org/t/terminate-android-program/5114/12 "2018-11-03T08:17:26Z")

</div>

@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

```auto

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

```

---

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 3, 2018, 8:27am UTC](https://discourse.processing.org/t/terminate-android-program/5114/13 "2018-11-03T08:27:37Z")

</div>

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…?

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 3, 2018, 8:43am UTC](https://discourse.processing.org/t/terminate-android-program/5114/14 "2018-11-03T08:43:01Z")

</div>

@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()”);

---

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 3, 2018, 8:54am UTC](https://discourse.processing.org/t/terminate-android-program/5114/16 "2018-11-03T08:54:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 3, 2018, 8:56am UTC](https://discourse.processing.org/t/terminate-android-program/5114/17 "2018-11-03T08:56:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 3, 2018, 8:58am UTC](https://discourse.processing.org/t/terminate-android-program/5114/18 "2018-11-03T08:58:51Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 3, 2018, 9:02am UTC](https://discourse.processing.org/t/terminate-android-program/5114/19 "2018-11-03T09:02:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gonadgranny](https://avatars.discourse-cdn.com/v4/letter/g/a88e4f/32.png) [@gonadgranny](https://discourse.processing.org/u/gonadgranny)
#### Post date: [November 3, 2018, 9:03am UTC](https://discourse.processing.org/t/terminate-android-program/5114/20 "2018-11-03T09:03:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 3, 2018, 12:01pm UTC](https://discourse.processing.org/t/terminate-android-program/5114/21 "2018-11-03T12:01:45Z")

</div>

@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.

[Next page](https://discourse.processing.org/t/terminate-android-program/5114.md?page=2)
