2013-07-13 68 views
0

在桌面Java應用程序中,我能夠重新啓動我的Java應用程序,其中一些腳本不需要進行編譯(例如,我們可以遠程添加一些額外的東西):Android - 如何重新啓動正在運行的應用程序,並且需要自行重新啓動?

桌面腳本: 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 & 

桌面應用程序:

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; 
    } 

如何重新啓動在Android中,像桌面? 我可以使用默認的BASH或其他默認的內置Android shell腳本嗎?或者還有一些其他方法可以執行一些未編譯的腳本來執行?

回答

1

取決於您要啓動的任務類型。 AFAIK你不能強迫你的活動在某種條件下回到全屏狀態,儘管用戶離開它(這也會讓我成爲用戶煩惱)。如果您需要在例如後期再次獲得後臺進程,系統重新啓動,在Android的消息傳遞系統上進行閱讀(Intent (class)/Intent (Docu))。您可以註冊某些關於系統事件的消息,並在您的處理程序代碼中添加一個例如服務,做一些後臺工作。
您可能需要查看this的實際操作示例。

類似Bash腳本的方法不存在,afaik。

相關問題