Skip to content

Commit

Permalink
Issue BasicAirData#56 - Workaround to a bug on Android 4.4.X on recreate
Browse files Browse the repository at this point in the history
  • Loading branch information
GrazianoCapelli committed Jan 26, 2020
1 parent 3233e11 commit c3eb1e4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
minSdkVersion 14
targetSdkVersion 28
versionCode 28
versionName '2.2.5b_20200122'
versionName '2.2.5b_20200126'
}
buildTypes {
debug {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,31 @@ public class GPSActivity extends AppCompatActivity {

@Override
public void onRestart(){
Log.w("myApp", "[#] " + this + " - onRestart()");

if (Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("prefColorTheme", "2")) != theme) {
Log.w("myApp", "[#] GPSActivity.java - it needs to be recreated (Theme changed)");
//this.recreate();
finish();
startActivity(new Intent(this, getClass()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Normal behaviour for Android 5 +
this.recreate();
} else {
// Workaround to a bug on Android 4.4.X platform (google won't fix because Android 4.4 is obsolete)
// Android 4.4.X: taskAffinity & launchmode='singleTask' violating Activity's lifecycle
// https://issuetracker.google.com/issues/36998700
finish();
startActivity(new Intent(this, getClass()));
}
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
super.onRestart();

Log.w("myApp", "[#] GPSActivity.java - onRestart()");
}


@Override
protected void onCreate(Bundle savedInstanceState) {
Log.w("myApp", "[#] " + this + " - onCreate()");

setTheme(R.style.MyMaterialTheme);
Log.w("myApp", "[#] GPSActivity.java - onCreate()");

theme = Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("prefColorTheme", "2"));

super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -147,16 +152,23 @@ public void onTabSelected(TabLayout.Tab tab) {

@Override
public void onStart() {
Log.w("myApp", "[#] " + this + " - onStart()");
super.onStart();

//Log.w("myApp", "[#] GPSActivity.java - onStart()");
activeTab = tabLayout.getSelectedTabPosition();
GPSApp.setGPSActivity_activeTab(activeTab);
}


@Override
public void onStop() {
Log.w("myApp", "[#] " + this + " - onStop()");
super.onStop();
}


@Override
public void onResume() {
Log.w("myApp", "[#] " + this + " - onResume()");
super.onResume();

// Workaround for Nokia Devices, Android 9
Expand All @@ -167,7 +179,6 @@ public void onResume() {
}

EventBus.getDefault().register(this);
Log.w("myApp", "[#] GPSActivity.java - onResume()");
LoadPreferences();
EventBus.getDefault().post(EventBusMSG.APP_RESUME);
if (menutrackfinished != null) menutrackfinished.setVisible(!GPSApp.getCurrentTrack().getName().equals(""));
Expand Down Expand Up @@ -226,38 +237,44 @@ public void onClick(DialogInterface dialog, int id) {
}
}


@Override
public void onPause() {
Log.w("myApp", "[#] " + this + " - onPause()");
EventBus.getDefault().post(EventBusMSG.APP_PAUSE);
Log.w("myApp", "[#] GPSActivity.java - onPause()");
EventBus.getDefault().unregister(this);
super.onPause();
}


@Override
public void onBackPressed() {
ShutdownApp();
}


@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
updateBottomSheetPosition();
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}


@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menutrackfinished = menu.findItem(R.id.action_track_finished);
menutrackfinished.setVisible(!GPSApp.getCurrentTrack().getName().equals(""));
return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
Expand Down

0 comments on commit c3eb1e4

Please sign in to comment.