Reputation: 69
I'm trying to implement an efficent navigation for my app; basically it's a product catalog, I mean:
list Product -> detail list Product (serach button in interface - startActivityForResult ) -> searchAct (cal finish) -> back to list Product (filtered)
but i need to open searchAct by the HW search button, and also from detail!
is it possible to use startActivityForResult from detail to open searchAct and when searchAct finish forward to list product? Also, if i open searchAct then press back i need to get back to detail!
if i use always:
startActivity()
then the user needs to press BACK button repeatedly, see all the steps...
for example if the usage is like this:
list (startActivity) ->detail (startActivity)->search (startActivity)->list (startActivity) ->detail
the back button works fine but i have to BACK 5 TIMES FOR EXIT!!
i try:
list (startActivity) ->detail (startActivity and finish() )->search (call finish()) ->list
BUT this way Back button in search is 'broken' because i got to list instead detail....
maybe i can try this:
detail (startActivityForResult) -> search
in detail if i got result_ok i finish() and get back to the list, if i got result_cancel i stay in detail?
i think i got it!!! in list activity i have 'classic' startActivityForResult then 'classic' onActivityResult
in detail activity i launch serach with startActivityForResult then:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
finish();
}
}
finishing the detail i got back to list.... i don't know if it's ok but i like it!
Upvotes: 3
Views: 581
Reputation: 10938
From the product detail activity, you are starting the search activity via startActivityForResult. In which case you can call finish() in the onActivityResult of the product detail activity when the search activity returns the correct code.
This way, the product detail will finish after a search and you'll end up back at the list activity.
If you start the product detail with startActivityForResult as well, you can return the data that your product activity gets given from the search activity.
I guessing this is what you want?
Upvotes: 1
Reputation: 2802
It's quite hard to understand whats your problem about, so im just guessing your need.
In your searchAct activity you can return data like this:
Intent returnIntent = new Intent();
String strData = "your data";
returnIntent.putExtra("data", strData);
setResult(RESULT_OK, returnIntent);
finish();
Then in your detail activity, from where you are starting searchAct, you have a function which is triggered when searchAct finish.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {}
Upvotes: 1