0

In desktop Java applications, i was able to restart my Java application by itself with some scripting not necessary to be compiled for example (so that remotely we can add some extra on stuff on it) as:

Desktop script: restartme.sh

#!/bin/bash
export DISPLAY=:0.0 
pkill java
java -cp SystemV.jar Main.Boot 0x01 &
# on the fly add new stuffs depending on the situations..
iperf -s -p 65000 & 
convert -size 800x600 xc:transparent -font Bookman-DemiItalic -pointsize 50 -draw "text 25,90 ' inactive.'" -channel RGBA -blur 0x6 -fill steelblue -stroke white -draw "text 10,90 ' inactive.'" -antialias /var/www/html/video/now.jpeg;
x11vnc -forever -passwd x1x &

Desktop application:

system("/var/tmp/restartme.sh &");

  public static String system(String cmds) {
    String value = "";
    try {
      String cmd[] = { "/bin/sh", "-c", cmds};
      Process p = Runtime.getRuntime().exec(cmd);
      p.waitFor();
      BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
      String line = reader.readLine();
      while (line != null) {
        value += line + "\n\r";
        line = reader.readLine();
      }
    } 
    catch (IOException ioe) {
      ioe.printStackTrace();
    } 
    catch (InterruptedException ie) {
      ie.printStackTrace();
    }
    return value;
  }

How do i restart in Android, like Desktop? Can i have default BASH or other default built-in Android shell scripting? Or there is some other way on the fly to do some not compiled scripts to be executed?

1 Answers1

0

Depends on what type of Task you want to start. AFAIK you can not force your activity to come back fullscreen on a certain condition although the user left it (and that also would annoy me as a user). If you need to get a background process up again after e.g. a system restart, read up on the messaging system in Android (Intent (class) / Intent (Docu)). You can register for certain message about system events and in your handler code spin up a e.g. service that does some background work.
You may want to take a look at this for a hands-on example.

A Bash-Script like approach doesn't exist, afaik.

Community
  • 1
  • 1
Janis F
  • 2,637
  • 1
  • 25
  • 36