Android intent pass data to activity - am i doing this right? -
Android intent pass data to activity - am i doing this right? -
another beginner android question...
i have imageview in activity called introduction. want alter image in imageview depending fling gesture. fling detection working fine, have
public class flinggesturelistener extends gesturedetector.simpleongesturelistener
which calls
private void raiseintent(string direction) { intent intent = new intent(demoapp.getappcontext(), introduction.class); intent.putextra("direction", direction); string category = demoapp.getappcontext().getstring(r.string.introduction_imageview_fling); intent.addcategory(category); intent.setflags(intent.flag_activity_new_task); demoapp.getappcontext().startactivity(intent); }
it primitive string "left" or "right" passed raiseintent on fling gesture.
introduction activity in imageview sits in view.
in app manifest activity have:
<activity android:name=".activities.introduction"> <intent-filter> <category android:name="@string/introduction_imageview_fling"/> </intent-filter> </activity>
so, in introduction activity can now, on resume, phone call
getintent
and pull out direction putextra. life good, can rely on value passed tell me image load imageview next.
my problem is, , lack of android knowledge may showing here, feels dirty.
im going have checks on intent on onresume create sure category @string/introduction_imageview_fling, , pull out data. know onresume called on oncreate gesture rasied within of activity after oncreate has been called. but, again, feels dirty me! best way pass info simpleongesturelistener activity? missing fundamental?
thanks
my follow far long comments, , contain , answer:
ok, solved nesting both
imageviewontouchlistener implements view.ontouchlistener
and
flinggesturelistener extends gesturedetector.simpleongesturelistener
within same activity. allowed me alter intent flag mode intent.flag_activity_single_top , wire up
public void onnewintent(intent intent) { }
and call
startactivity(intent);
as apposed
demoapp.getappcontext().startactivity(intent);
where demoapp application file , context singleton. ok fine, works expect , life good!
but, have nested classes , could, far novice mind can tell, end violating dry. when trying phone call flag_activity_single_top separate class told error log the
flag_activity_new_task
can called outside activity, , makes sense in cases activity might have been nuked off stack, or never started @ all. in illustration here, 1 activity, separate class files, way solve this? or looking @ wrong angle?
thanks again.
android android-intent
Comments
Post a Comment