下午好。我开始用java和黑莓编程。我正在开发一个带有三个窗口的应用程序,我将显示有关设备的基本信息,这些窗口已经完成并正在工作。我需要创建一个在后台运行的进程,这个进程将每 10 分钟运行一次。当我让这个过程在后台运行并正在关闭窗口时?
这是运行应用程序的类型:
public class InfoBerry extends UiApplication{
public vtnprincipal vtnprincipal;
public vtnbateria vtnbateria;
public vtnestado vtnestado ;
public vtnacerca vtnacerca;
public InfoBerry(){
}
public static void main(String[] args) {
InfoBerry theApp = new InfoBerry();
theApp.mostrarpantalla();
}
public void mostrarpantalla(){
vtnprincipal = new vtnprincipal(this);
vtnbateria = new vtnbateria(this);
vtnestado = new vtnestado(this);
vtnacerca = new vtnacerca(this);
// Inicailizamos los componentes de la pantalla principal
vtnprincipal.incventana();
// La pnemos en lo alto de la pila de pantallas
pushScreen(this.vtnprincipal);
}
}
这是您需要在后台运行的类。因为我必须调用这个类才能在后台运行?
class iconnoti extends MainScreen{
//icono de la temperatura
EncodedImage imgtem =
EncodedImage.getEncodedImageResource("icon_bateria_t.png");
ApplicationIcon icontem = new ApplicationIcon(imgtem);
//icono de la carga de la bateria
EncodedImage imgcarga =
EncodedImage.getEncodedImageResource("icon_bateria.png");
ApplicationIcon iconcarga = new ApplicationIcon(imgcarga);
//icono de la memoria
EncodedImage imgmemo =
EncodedImage.getEncodedImageResource("icon_memoria.png");
ApplicationIcon iconmemo = new ApplicationIcon(imgmemo);
ApplicationIcon mIcon = icontem;
boolean act;
public iconnoti() {
}
public void rotar_temperatura(){
cron c1;
actualizar_icono(icontem);
actualizar_valor(DeviceInfo.getBatteryTemperature());
c1 = new cron(2,10000);
c1.start();
}
public void rotar_memoria(){
cron c1;
actualizar_icono(iconmemo);
actualizar_valor(34);
c1 = new cron(3,10000);
c1.start();
}
public void rotar_nivel(){
cron c1;
actualizar_icono(iconcarga);
actualizar_valor(DeviceInfo.getBatteryLevel());
c1 = new cron(1,10000);
c1.start();
}
public void iniciar_servicio() {
try {
ApplicationIndicatorRegistry reg =
ApplicationIndicatorRegistry.getInstance();
ApplicationIndicator Indicator =
reg.register(mIcon, false, true);
} catch (Exception e) {
}
}
public void parar_servicio() {
try {
ApplicationIndicatorRegistry reg =
ApplicationIndicatorRegistry.getInstance();
reg.unregister();
} catch (Exception e) {
}
}
void actualizar_valor(int value) {
try {
ApplicationIndicatorRegistry reg =
ApplicationIndicatorRegistry.getInstance();
ApplicationIndicator appIndicator =
reg.getApplicationIndicator();
appIndicator.setValue(value);
} catch (Exception e) {
}
}
void actualizar_icono(ApplicationIcon icon) {
try {
ApplicationIndicatorRegistry reg =
ApplicationIndicatorRegistry.getInstance();
ApplicationIndicator appIndicator =
reg.getApplicationIndicator();
appIndicator.setIcon(icon);
} catch (Exception e) {
}
}
}
class cron extends Thread {
//private ApplicationIcon icono;
public int valor;
private int tiempo;
iconnoti icon = new iconnoti();
public cron(int v, int t){
valor = v;
tiempo = t;
}
public void run() {
try {
sleep(tiempo);
} catch (InterruptedException e) {
}
if(valor == 1){
icon.rotar_temperatura();
}else if(valor == 2){
icon.rotar_memoria();
}else if(valor == 3){
icon.rotar_nivel();
}
}
}
谢谢您的帮助。