Change ImageView from another activity - android

I have a ListView with some buttons lets say every list has button_1 and button_2 when i click button_1 i will go to next intent but will not finish() the previews activity and then on my present activity there is a button_3 and if i click button_3 the button_2 from previous activity will change too when i go back. now my question is is there a way we can pass a view from another activity or is it possible to call setNotifyOnChange() on another activity?

just call setNotifyOnChange() in onResume() method of the previous activity

Related

Android back pressed without refresh activity

I have 2 activities which one activity leads to the other activity.
The first activity present a listview and the items click leads to the second activity.
When I click the back button I get back to the first activity but the list reload and scroll up to the first item. I want the list to stay at its place after I get back to it.
If you call finish() in activity A when openig the new Activity B on back press you will call onCreate() of activity A to avoid this avoid calling finish() in activity A in your onItemClickListner()of activity A and record tge position of tge click in Activity A, in which case calling the back press in Activity B will cll for tge onResume() in activity A where in you could call For a direct scroll:
getListView().setSelection(<position>);
Or For a smooth scroll:
getListView().smoothScrollToPosition(<position>);
when you press back you call oncreate() on that activity so everything reload
you could use :
getListView().smoothScrollToPosition(yourpostion);
and think about using fragments for another way around it .
and recyclerview is advised .
If you don't call finish() on Activity A, even if you go to Activity B and come back, Activity A should not call the whole onCreate() again.
If you take a look at the life cycle of Activities, it will put Activity A in onPause() and probably onStop() depending on what you are doing on Activity B and how you defined launchMode in AndroidManifest.xml.
So when you are calling startActivity(..), don't call finish(). Otherwise it will load everything again to draw the Activity A.
Another possible way is using
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
..
}
OR you can use SharedPreference.
Once fetching data from Parse.com is over (like onPostExecute() of AsyncTask), you can read the data passed from Activity B to relocate the user to the list where they were.
EDIT:
Read this article about how to "come back" to the activity you were in, too.

Android, EditText preservation through new activities

How can I preserve data between activities? For instance, I have an edit text and a button in Activity A. I fill in that editText and then click on the button. That button starts a new intent, Activity B. In B there are several buttons, but all of them if clicked on, start activity A again. I want that editText to be still filled in as well as pass specific data to Activity A depending on the button pressed in Activity B.
I know this has to do with onStop() -> onStart(), but couldn't get it to work.
You should start Activity B with startActivityForResult. Then, when u set the result, you should "catch" it in Activity A by overriding onActivityResult().
As for EditText, if you don't call finish() on Activity A - you don't need to override onSaveInstanceState or anything else - system does it for you.
Don't finish the activity in Activity A intent to Activity B. and use startActivityForResult(intent) rather than startActivity(intent) to be able to pass the data back to activity A again. check this answer to how How to manage `startActivityForResult` on Android?.

fire onPause on device back button but not on button click

I am opening new activity on button click of one activity. New Activity contains image button named go back. Now I want that when anyone click on back button of mobile device, it fires onPause or say close the application but when anyone clicks on go back image button, application does not fire onPause and it goes on last activity.
How to do it ?
If you have called finish() in your first activity while coming to this second activity and if you want to go to first activity again on click event of "go back" button in second activity, then you need to call an Intent to go from second activity to first activity.
But if you do not call finish() in your first activity while coming to this second activity and you want to go to first activity again on click event of "go back" button in second activity then simply call finish() on click event of "go back" button in second activity.
I saw your code from your other question, so you need to remove the finish() from onPause and add finish() to your "go back" button listener.
Do not call finish() if you want to keep it on the stack (in order to go back).
Example:
Activity A starts Activity B, which starts Activity C. (no finish() called yet)
Then when you go back from C, call finish() and you will
see Activity B.
Then when you go back from B, call finish() and you will see Activity A.
This is how you can pass values between different activities.
Intent i = new Intent(A.this, B.class);
i.putExtra("numbers", array);
startActivity(i);

Handling back button with multiple activities

In my main activity, when you click a button, it launches a new activity (act2), in which another activity (act3) is loaded onCreate (assuming it was launched by that specific button only)
act3 is a listview, selecting an item returns you to act2 and sets a textview accordingly. If you press the back button in act3 it takes you to act2. However, if act3 originated from that specific button and no item is selected I would like for it to take you back to the main activity instead. What is the best way to handle this?
Set the activity result of act3 to RESULT_OK if something was selected before finishing. in onActivityResult in act2, if the result was RESULT_CANCELLED, finish(). If it was RESULT_OK, process the returned value.

How to implement Back button functionality

I have 3 different activity namely, category,sub_category and list of items. In sub_category i created back button using intent Activity. Back button in list_of items should be focus to sub_category. i dont know how to do this.. pls guide me..
from category activity
call
Intent it=new Intent(category.this,sub_category.class)
startActivityForResult(it);
similarly
Intent it=new Intent(sub_category.this,list_item.class)
startActivityForResult(it);
and in onClickListener of back button simply finish your activity like
list_item.this.finish();
for going back to previous screen u can call finish() in your current activity. It will remove the current activity from activity Stack and take you to the previous one.

Categories

Resources