Reputation: 177
What I want is that when I lose focus and return to my app, it continues where it left off. To show the problem I have created a 45 second video at this link enter link description here
The same thing happens when running simulator. In the main class I make use of Lifecycle (generated from CN1).
I am copying the main class to it for validation. MainClass
public class TarifaTaxiPredictivo extends Lifecycle {
private Usuario iU;
@Override
public void runApp() {
String sIdioma = L10NManager.getInstance().getLanguage().toLowerCase();// Salva el tipo de idioma
if (!sIdioma.equals(IDIOMA_INGLES) && !sIdioma.equals(IDIOMA_ESPANOL)) {
sIdioma = IDIOMA_ESPANOL;
}
iU = Usuario.getInstancia();
iU.setIdioma(sIdioma);
iU.setAumento(calculatePorcentajeAumento());
showSplashAnimation();
}
public void showSplashAnimation() {
Form splash = new Form(new LayeredLayout());
splash.setUIID("Splash");
ScaleImageLabel iconBackground = new ScaleImageLabel(getGlobalResources().getImage("attt.png"));
iconBackground.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
Container centerBackground = BorderLayout.center(iconBackground);
splash.add(centerBackground);
Label iconForeground = new Label(getGlobalResources().getImage("attt.png"));
Container centerIcon = BorderLayout.centerAbsolute(iconForeground);
splash.add(centerIcon);
splash.show();
Display.getInstance().callSerially(() -> {
((BorderLayout) centerBackground.getLayout()).setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
centerBackground.setShouldCalcPreferredSize(true);
centerBackground.animateLayoutAndWait(2000);
iconForeground.remove();
iconBackground.remove();
centerIcon.remove();
Container cnFondo = LayeredLayout.encloseIn(
new Label(iconBackground.getIcon(), "CenterIcon"));
Container boxy = BoxLayout.encloseY(cnFondo);
Label placeholder = new Label();
placeholder.setShowEvenIfBlank(true);
Label lbTit = new Label("Tarifa de Taxi", "SplashSubTitulo");
Component.setSameHeight(placeholder, lbTit);
Component.setSameWidth(placeholder, lbTit, boxy);
centerBackground.add(BorderLayout.CENTER, boxy);
splash.revalidate();
Display.getInstance().callSerially(() -> {
placeholder.setText(" ");
boxy.add(placeholder);
boxy.setShouldCalcPreferredSize(true);
boxy.getParent().animateLayoutAndWait(1500);
boxy.replaceAndWait(placeholder, lbTit, CommonTransitions.createFade(1500));
Label lbNuevoTitulo = new Label(" ");
Label lbTitulo = new Label("ATTT", "SplashTitulo");
Component.setSameHeight(lbNuevoTitulo, lbTitulo);
Component.setSameWidth(lbNuevoTitulo, lbTitulo);
boxy.add(lbNuevoTitulo);
boxy.getParent().animateLayoutAndWait(250);
boxy.replaceAndWait(lbNuevoTitulo, lbTitulo, CommonTransitions.createFade(3000));
new Tarifa().show();
});
});
}
}
Upvotes: 1
Views: 46
Reputation: 52770
This is OS behavior. When an app is sent to the background the stop()
method is invoked. It's important that we stop all connections etc. otherwise the phone will kill the app to preserve battery life.
When the app is restored start()
will be invoked again. If your app always restarts when start()
is invoked then you will get the effect of a clean restart.
You can test this in the simulator via the pause/resume functionality. You will be able to see how your app is supposed to act when the phone pauses it and restores it.
Assuming this works correctly in the simulator but fails in the device this would be because you're using resources in the background which you can only do through a background service facility.
Upvotes: 0