I have read a lot but still havn't got my full answer. When starting app A,within onCreate method I get data from Api and set on ListVie开发者_开发百科w. Here also I have button and when I click to it I am going to Activity B and send some data. Within my B activity I send data to my api and if response status is ok I want to go back to activity A and reload data:call oncreate method in wich located my call function to api. In my manifest I have set
<activity android:name=".A"
android:launchMode="singleInstance" ></activity>
but when I call startActivity:
Intent i = new Intent(B.this,A.class);
Bundle b = new Bundle();
String from = "upload";
b.putString("action", from);
startActivity(i);
I dont start activty A from point onCreate. I have already tried call finish() function after going to activity B but this doesn't get my any result. I want to append that in A activity I get file from gallery and pass uri to activity B.
Thanks.
If you want to start a child activity with the intention of receiving a result, don't use startActivity()
. Use startActivityForResult()
instead. You will also need to implement (override) a method in your main activity to be called when the result is ready.
If you want to get back to A and you need onCreate
call finish()
in A after startActivity(B)
. This way, onCreate
will get called again when you go back to A (since it was destroyed).
Note that this is not a good way to handle things. A better method would be to move the "getting data from Api" part to onResume
in activity A.
LATER EDIT: Indeed, startActivityForResult()
is the way to go in this situation, no need to over-complicate things. Note to self: go for the easier route from now on.
精彩评论