java - Good architecture for detecting Android device shake event? -
i need start activity
in case of device shake in android application
.
this feature should work in whole app
, in activities.
now sure how provide architecture it, because detecting shake , starting activity needs context instance.
i don't want pass current activity instance shakelistener
each time change activity
.
what suggest?
thanks.
you would have to keep around monitors sensor data, background service. service must continuously monitor sensor events, pass through noise filter, detect shake , send out broadcast.
the activity on other hand can implement matching broadcastreciever.
if don't want add broadcastrecievers activities, can register interested activities in init()
code of library:
public void init(context context){ sensortester st = new sensortester(context); st.registeractivity(mainactivity.class); st.registeractivity(otheractivity.class); }
and start them library service using context received in init()
code:
for(class c : registeredclasses){ context.startactivity(new intent(this,c)); }
where want place init()
code in target app choice.
Comments
Post a Comment