Browse Source

Avoid creating new remote and beamer instances in onCreate()

Maurizio Porrato 2 months ago
parent
commit
661ef08e58
1 changed files with 10 additions and 7 deletions
  1. 10
    7
      app/src/main/java/eu/worn/apps/androvac/MainActivity.java

+ 10
- 7
app/src/main/java/eu/worn/apps/androvac/MainActivity.java View File

@@ -44,14 +44,17 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
44 44
         super.onCreate(savedInstanceState);
45 45
         setContentView(R.layout.activity_main);
46 46
 
47
-        remote = new RoboVac11sRemote();
47
+        if (remote == null)
48
+            remote = new RoboVac11sRemote();
48 49
 
49
-        beamer = new AndroidIRBeamer(this);
50
-        if (!beamer.isAvailable()) {
51
-            Toast.makeText(this.getApplicationContext(),
52
-                    "No IR beamer found: entering debug mode",
53
-                    Toast.LENGTH_LONG).show();
54
-            beamer = new DebugIRBeamer(this);
50
+        if (beamer == null) {
51
+            beamer = new AndroidIRBeamer(this);
52
+            if (!beamer.isAvailable()) {
53
+                Toast.makeText(this.getApplicationContext(),
54
+                        "No IR beamer found: entering debug mode",
55
+                        Toast.LENGTH_LONG).show();
56
+                beamer = new DebugIRBeamer(this);
57
+            }
55 58
         }
56 59
 
57 60
         findViewById(R.id.schedule).setEnabled(

Loading…
Cancel
Save