diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java
index 7562c2a21..3785249b4 100644
--- a/app/src/main/java/org/schabi/newpipe/App.java
+++ b/app/src/main/java/org/schabi/newpipe/App.java
@@ -65,7 +65,6 @@ public class App extends MultiDexApplication {
public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID;
private static final String TAG = App.class.toString();
private static App app;
- private static boolean wasAppInForeground = false;
@NonNull
public static App getApp() {
@@ -256,11 +255,4 @@ public class App extends MultiDexApplication {
return false;
}
- public static boolean wasAppInForeground() {
- return wasAppInForeground;
- }
-
- public static void setWasAppInForeground(final boolean wasAppInForeground) {
- App.wasAppInForeground = wasAppInForeground;
- }
}
diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
index 64874cd93..9c392be1e 100644
--- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
+++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
@@ -235,6 +235,23 @@ public final class CheckForNewAppVersion extends IntentService {
}
}
+ /**
+ * Start a new service which
+ * checks if all conditions for performing a version check are met,
+ * fetches the API endpoint {@link #NEWPIPE_API_URL} containing info
+ * about the latest NewPipe version
+ * and displays a notification about ana available update.
+ *
+ * Following conditions need to be met, before data is request from the server:
+ *
+ * - The app is signed with the correct signing key (by TeamNewPipe / schabi).
+ * If the signing key differs from the one used upstream, the update cannot be installed.
+ * - The user enabled searching for and notifying about updates in the settings.
+ * - The app did not recently check for updates.
+ * We do not want to make unnecessary connections and DOS our servers.
+ *
+ * Must not be executed when the app is in background.
+ */
public static void startNewVersionCheckService() {
final Intent intent = new Intent(App.getApp().getApplicationContext(),
CheckForNewAppVersion.class);
diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java
index ed3826946..2a8872e26 100644
--- a/app/src/main/java/org/schabi/newpipe/MainActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java
@@ -166,6 +166,15 @@ public class MainActivity extends AppCompatActivity {
openMiniPlayerUponPlayerStarted();
}
+ @Override
+ protected void onPostCreate(final Bundle savedInstanceState) {
+ super.onPostCreate(savedInstanceState);
+ // Start the service which is checking all conditions
+ // and eventually searching for a new version.
+ // The service searching for a new NewPipe version must not be started in background.
+ startNewVersionCheckService();
+ }
+
private void setupDrawer() throws Exception {
//Tabs
final int currentServiceId = ServiceHelper.getSelectedServiceId(this);
@@ -516,19 +525,6 @@ public class MainActivity extends AppCompatActivity {
getString(R.string.enable_watch_history_key), true);
drawerLayoutBinding.navigation.getMenu().findItem(ITEM_ID_HISTORY)
.setVisible(isHistoryEnabled);
-
- if (!App.wasAppInForeground()) {
- // Check for new app version
- // The service searching for a new NewPipe version must not be started in background
- // and therefore needs to be placed in onResume().
- // Only start the service once when app is started
- // and not everytime onResume() is called.
- if (DEBUG) {
- Log.d(TAG, "App is in foreground for the first time");
- }
- App.setWasAppInForeground(true);
- startNewVersionCheckService();
- }
}
@Override