0

I recently started Android Development and am creating an app that measures certain SIM data, however when some data about the SIM changes mainActivity recreates itself each time certain data changes so I lose all the old data that I need to log and keep track of. How do i prevent mainActivity from recreating itself more than once?

1 Answers1

0

Sounds like changing the sim causes a configuraiton change. Add onConfigChange to your manifest and list... basically I'd put in everything, then you can pull stuff out until you find the minimal set. I have no idea what config changes a sim might cause.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • well this a special kind of sim for gsm devices that acts as if its roaming so the configuration changes accordingly, hopefully that clears things up – Shivam Dave Aug 05 '16 at 18:57
  • Sp setting it to mcc|mnc is probably enough. Add locale for good measure, although it shouldn't be needed. – Gabe Sechan Aug 05 '16 at 18:59
  • well my question is how can i save the data im logging before the activity ultimately restarts – Shivam Dave Aug 05 '16 at 19:01
  • In onSaveInstanceState, like every other time the activity does recreation. – Gabe Sechan Aug 05 '16 at 19:02
  • Forgive me for being a noob, but that will that mean all my initializing code in onCreate will be saved and carried on after the reconfig happens – Shivam Dave Aug 05 '16 at 19:04
  • It means that in onCreate you'd check if the savedInstanceState bundle is null or not. If its non-null, read in the info from the bundle. If its null, this is not a recreation and you initialize normally – Gabe Sechan Aug 05 '16 at 19:05
  • https://developer.android.com/guide/topics/resources/runtime-changes.html would the Fragment work as well? – Shivam Dave Aug 05 '16 at 19:09