Add onStart function

Add the OnStart function (see lifecylce), which will be executed after 
`onCreate` and when the app is restarted (from inactivity)
This commit is contained in:
Finn M Glas 2020-05-17 07:25:57 +02:00
parent 73d01a8b46
commit 9f48a13d33

View file

@ -114,7 +114,6 @@ GestureDetector.OnDoubleTapListener {
return true return true
} }
@SuppressLint("SetTextI18n") // I do not care
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -126,8 +125,6 @@ GestureDetector.OnDoubleTapListener {
if (!sharedPref.getBoolean("startedBefore", false)) if (!sharedPref.getBoolean("startedBefore", false))
startActivity(Intent(this, FirstStartupActivity::class.java)) startActivity(Intent(this, FirstStartupActivity::class.java))
loadSettings(sharedPref)
// Flags // Flags
window.setFlags( window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN,
@ -135,18 +132,29 @@ GestureDetector.OnDoubleTapListener {
) )
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
setContentView(R.layout.activity_main)
}
// After the app is created or when it restarts (inactivity) - Fixes Issue #9
override fun onStart(){
super.onStart()
// Preferences
val sharedPref = this.getSharedPreferences(
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
loadSettings(sharedPref)
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault()) val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
fixedRateTimer("timer", false, 0L, 1000) { fixedRateTimer("timer", false, 0L, 1000) {
this@MainActivity.runOnUiThread { this@MainActivity.runOnUiThread {
dateView.text = dateFormat.format(Date()) dateView.text = dateFormat.format(Date())
timeView.text = timeFormat.format(Date()) // not " GMT" timeView.text = timeFormat.format(Date())
} }
} }
setContentView(R.layout.activity_main)
mDetector = GestureDetectorCompat(this, this) mDetector = GestureDetectorCompat(this, this)
mDetector.setOnDoubleTapListener(this) mDetector.setOnDoubleTapListener(this)
} }