Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Activity Navigation, Back to prev Activity and Back to 'exit'

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!

like image 630
Stefano IceCubeR Avatar asked Nov 30 '25 21:11

Stefano IceCubeR


1 Answers

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) {}
like image 60
timoschloesser Avatar answered Dec 03 '25 11:12

timoschloesser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!