android - Activity get's recreated although I call finish -
background
i use helper activity determine when floating widget (placed in windowmanager
) opens activity, need hide floating widget then...
therefore create transparent activity, checks in onpause
if screen turned off or not. if not, assume activity opened floating widget.
problem
opening recent apps lead hide floating widget , finish helper activity, desired.
but pressing afterwards, recreates helper activity. , helper activity shown in recent apps (although finished it).
usage , log
i open activity @ 1 place following:
l.d(this, "helperactivity created"); intent = new intent(getcontext(), helperactivity.class); i.addflags(intent.flag_activity_new_task); i.putextra("sidebarid", msidebar.getid()); getcontext().startactivity(i);
and log says:
[sidebarview-241] helperactivity created [helperactivity-30] oncreate: 1
<< pressing recent apps button on phone >>
[helperactivity-69] new top [helperactivity-45] onsidebarcloseevent [helperactivity-36] ondestroy
<< showing recent apps >>
[helperactivity-30] oncreate: 1
code
manifest:
<activity android:name=".activities.helperactivity" android:configchanges="orientation|screensize" android:excludefromrecents="true" android:nohistory="true" android:theme="@style/theme.transparent" android:launchmode="singletask" />
class:
public class helperactivity extends appcompatactivity { private boolean mdocheck = true; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); busprovider.getinstance().register(this); setcontentview(r.layout.activity_helper); long sidebarid = -1; if (getintent().getextras().containskey("sidebarid")) sidebarid = getintent().getextras().getlong("sidebarid"); l.d(this, "oncreate: " + sidebarid); } @override public void ondestroy() { l.d(this, "ondestroy"); busprovider.getinstance().unregister(this); super.ondestroy(); } @subscribe public void onsidebarcloseevent(sidebarcloseevent event) { l.d(this, "onsidebarcloseevent"); mdocheck = false; finish(); } @override public void onpause() { super.onpause(); if (!mdocheck) return; // pause + screenon => andere activity on top! powermanager pm = (powermanager) getsystemservice(power_service); boolean screenon; if (build.version.sdk_int >= build.version_codes.kitkat_watch) screenon = pm.isinteractive(); else screenon = pm.isscreenon(); if (screenon) { l.d(this, "new top"); busprovider.getinstance().post(new sidebarcloseevent(null, true, false)); } } }
current solution
i worked out following solution:
in oncreate
use following:
boolean launchedfromhistory = (flags & intent.flag_activity_launched_from_history) == intent.flag_activity_launched_from_history; if (launchedfromhistory) finish();
this seems work... still, maybe has comment solution or knows better...
Comments
Post a Comment