Issue
I think I need to put some code within my onStop
method. It pertains to a service that should be running only when the activity is finished()
but when the user follows some linkify
'd text to the web browser, or when the user presses the homescreen, both call onStop()
but these do not end the activity, I don't want to end the activity when a user follows a link, so I can't put finish()
within onStop()
unless I can detect and differentiate when this happens within onStop()
is there a way I can override Linkify()
so that I can add a flag within it, or maybe make it run startActivityforResult()
so that I can information back in a result?
similarly, is there a way I can set the activity to finish()
when the user presses the home button?
Thanks
Solution
Is it possible for you to check isFinishing()
in your onStop()
to decide whether you need to run the service-related code or not?
@Override
protected void onStop() {
super.onStop();
if (isFinishing()) {
// Your service-related code here that should only run if finish()
// was called.
}
}
UPDATE: (after understanding the problem better)
Very similar to my suggested approach on another question, you can probably override startActivity()
to intercept when the link is launching and set your flag if that's the case.
@Override
public void startActivity(Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_VIEW)) {
// maybe also check if getScheme() is 'http' then set our flag
persist.saveToPrefs("linkifyClick", true);
}
// proceed with normal handling by the framework
super.startActivity(intent);
}
That other answer also show how you can call startActivityForResult()
too instead if you want.
Answered By - Joe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.