android - How do I prevent device rotation from generating duplicate output? -


after user inputs parameters in mainactivity app (shown below), taps search, calls matchesactivity, generates output on new screen (shown further below), exited via tapping back.

enter image description here

but matchesactivity active, every time device rotated, search again executed because activity restarts. in screenshot below, rotated device vertical horizontal vertical horizontal vertical.

enter image description here looks silly.

the output generated in matchesactivity invoked in oncreate in mainactivity so:

intent matchesintent; matchesintent = new intent(mainactivity.this, matchesactivity.class); startactivity(matchesintent); 

here's essence of oncreate matchesactivity:

@override protected void oncreate(bundle savedinstancestate) {       mainactivity.dbc.setdbprocesslistener(this); // know txamatches has been defined    mainactivity.dbc.finddbmatches(); // generate output } 

i did research. found complicated ways of preventing activity restarting when device rotated. for example .

i'm hoping simpler solution. ideas?

as have found, 1 option prevent activity being recreated on configuration changes together. not best option, prevent other things depending on configuration being recreated/reloaded (e.g. resources overridden "-land" qualifier).

another option cache result of db search somehow. done adding wrapper around database memorizes term , results of last search. way cache results use fragment, , reuse fragment across activity recreations. whether fragment recreated along activity controlled method: http://developer.android.com/reference/android/app/fragment.html#setretaininstance(boolean).


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

python - malformed header from script index.py Bad header -