Tag Archives: activity

3,141 views

How to save the state of Activity – Android

onSaveInstanceState, onRestoreInstanceState , save preferences int mCurrentPhotoIndex = 0; @Override protected void onSaveInstanceState(Bundle outState) { outState.putInt("photo_index", mCurrentPhotoIndex); super.onSaveInstanceState(outState); }   @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { mCurrentPhotoIndex = savedInstanceState.getInt("photo_index"); super.onRestoreInstanceState(savedInstanceState); }   // or save preferences for new start of … Continue reading

Posted in Android Examples Code | Tagged , | Comments Off on How to save the state of Activity – Android
4,477 views

Start an new Activity Intent with a parameter Android example

putString(), putBoolean(), putInt() etc.¨ How we can start an activity programmatically. // MainActivity.java // myButton.setOnClickListener Intent binary = new Intent(getApplicationContext(),Calculate.class); Bundle b = new Bundle(); b.putString("prvni_label", "Decimal"); b.putString("druhy_label", "Binary"); b.putString("mode", "binary_to_decimal"); binary.putExtras(b); startActivityForResult(binary, 0);   // in Calculate.java onCreate   … Continue reading

Posted in Android Examples Code | Tagged , | Comments Off on Start an new Activity Intent with a parameter Android example
6,344 views

Activity lifecycle if application reopened Android emulator example

First step was hidden application after HOME button was pressed. Second step is restart application if user clicked on application’s icon. 20:35:54.028: VERBOSE/BackupManagerService(60): Backup requested but nothing pending   // reopen – rerstart application if long time is emulator disuse … Continue reading

Posted in Android Examples Code | Tagged , , | Comments Off on Activity lifecycle if application reopened Android emulator example
5,136 views

Activity Lifecycle if button Home pressed Android example

If on Android emulator home button pressed. // button home presssed 19:37:06.727: INFO/ActivityManager(60): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher } from pid 60   19:37:06.807: INFO/onSaveInstanceState(339): onSaveInstanceState() 19:37:06.848: INFO/onPause(339): onPause() 19:37:07.968: INFO/onStop(339): onStop() Diagram of Activity lifecycle if button … Continue reading

Posted in Android Examples Code | Tagged , , | Comments Off on Activity Lifecycle if button Home pressed Android example
54,141 views

Start Activity from ListView item click Android example

How start certain Activity if user clicked to ListView item Start Activity from list – launches other activities from list – latest variant!!!! public class Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);   try { setContentView(R.layout.main); … Continue reading

Posted in Android Examples Code | Tagged , , , , , , | Comments Off on Start Activity from ListView item click Android example