performance - Switching between Android activities increasing memory usage -
an app consists of 3 activities: activity a, b , c. each activity has "singletop" set launch mode.
all 3 activities have default "hello world!" textview , button. button in activity starts activity b , 1 in activity b starts activity c. code use:
public void startactivityb(view v){ intent = new intent(a.this, b.class); i.addflags(intent.flag_activity_single_top|intent.flag_activity_clear_top); startactivity(i); }
the button in activity c finishes using finish()
i know there similar questions have tried every single thing make work nothing has worked me. problem if navigate b , b c, c b , b using android's button, , repeat process several times, reason there several instances of each activity, except a, running. used mat check , there several objects of each class when there should 1 of each.
my concern happening memory app uses keeps increasing end in app getting "oom" error.
am doing wrong or missing something?
activity a
package com.test.testapp; import android.content.intent; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.view; public class extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_a); } public void startactivityb(view v){ intent = new intent(a.this, b.class); i.addflags(intent.flag_activity_single_top|intent.flag_activity_clear_top); startactivity(i); } }
activity b
package com.test.testapp; import android.content.intent; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.view; public class b extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_b); } public void startactivityc(view v) { intent = new intent(b.this, c.class); i.addflags(intent.flag_activity_single_top | intent.flag_activity_clear_top); startactivity(i); } }
activity c
package com.test.testapp; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.view; public class c extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_c); } public void closeactivity(view v){ finish(); } }
update
activities still have several instances when changing launch mode , starting them different intent flags. reason if call finish() on activities problem persists.
Comments
Post a Comment