Created
November 8, 2018 03:13
-
-
Save mnafian/b06987a7ab6bf634f53c00c5511ac41c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.myapplication | |
import android.os.Bundle | |
import android.support.v7.app.AppCompatActivity | |
import android.util.Log | |
import kotlinx.android.synthetic.main.activity_main.* | |
class MainActivity : AppCompatActivity() { | |
private val TAG = MainActivity::class.java.simpleName | |
private var savedKey = "Halo" | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
if (savedInstanceState != null) { | |
Log.d(TAG, "onCreate() Restoring previous state"); | |
/* restore state */ | |
savedKey = savedInstanceState.getString("savedKey") | |
} else { | |
Log.d(TAG, "onCreate() No saved state available"); | |
/* initialize app */ | |
} | |
button.setOnClickListener { | |
Log.e("test", "klik") | |
} | |
} | |
override fun onRestoreInstanceState(savedInstanceState: Bundle?) { | |
if (savedInstanceState != null) { | |
Log.d("savedKey", savedInstanceState.getString("savedKey")); | |
/* restore state */ | |
} else { | |
Log.d(TAG, "onCreate() No saved state available"); | |
/* initialize app */ | |
} | |
} | |
override fun onSaveInstanceState(outState: Bundle?) { | |
outState?.run { | |
putString("savedKey", savedKey) | |
} | |
super.onSaveInstanceState(outState) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment