How can I refresh a previous activity after the back button is pressed?
You should probably override your onResume() to check if the list of alarms have been refreshed so that whenever you come to/come back to your ListActivity, it'll get updated.
Refresh activity on back button
onPause() is called in Activity A when it launches Activity B. After the back button is called in Activity B, onResume() is called in Activity A.
You should load comments (api/server call) in onResume function rather than onCreate function of Activity A so that every time the activity is resumed your comments are refreshed.
How can I restart activity on back button pressed?
You could just override the onBackButton pressed in your second activity to start the first one. Example:
@Override
public void onBackPressed() {
startActivity(new Intent(this, FirstActivity.class));
}
refresh fragment that gone to activity after back pressed in that activity
Let's say you have two two activities A and B.Initially Fragment f1 is added to A.When you click on item in f1 start activity B with startActivityForResult (Intent intent, int requestCode) and in onActivityResult(int requestCode, int resultCode, Intent data) either update the fragment data(if possible) or reload the fragment.
How to go back and refresh the previous page in Flutter?
You can trigger the API call when you navigate back to the first page like this pseudo-code
class PageOne extends StatefulWidget {
@override
_PageOneState createState() => new _PageOneState();
}
class _PageOneState extends State<PageOne> {
_getRequests()async{
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new RaisedButton(onPressed: ()=>
Navigator.of(context).push(new MaterialPageRoute(builder: (_)=>new PageTwo()),)
.then((val)=>val?_getRequests():null),
),
));
}
}
class PageTwo extends StatelessWidget {
@override
Widget build(BuildContext context) {
//somewhere
Navigator.pop(context,true);
}
}
Or you can just use a stream if the API is frequently updated, the new data will be automatically updated inside your ListView
For example with firebase we can do this
stream: FirebaseDatabase.instance.reference().child(
"profiles").onValue
And anytime you change something in the database (from edit profile page for example), it will reflect on your profile page. In this case, this is only possible because I am using onValue
which will keep listening for any changes and do the update on your behalf.
After pressing back button, previous activity (listview) is emtpty
try this on AllStudents
activity
@Override
protected void onResume() {
super.onResume();
if (studentList != null && studentList.size()>0) {
ListAdapter adapter = new ListAdapter(studentList, this);
StudentListView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
*Note
when you make a search you run the filterStudents()
method
and replace the current list in the adapter
ListAdapter adapter = new ListAdapter(filteredList, this);
but make sure that if you search for nothing .. return the original list
ListAdapter adapter = new ListAdapter(studentList, this);
or you will get an empty list view
Related Topics
Android: How to Open a Specific Folder Via Intent and Show Its Content in a File Browser
Check Programmatically If App Is Installed on the Device
Update Some Specific Field of an Entity in Android Room
Sending Files Using Post With Httpurlconnection
How to Convert Android.Media.Image to Bitmap Object
Android Volley Basicnetwork.Performrequest() Unexpected Response Code 404
Error: Open Failed: Enoent (No Such File or Directory)
Apk Installation Failed: [Install_Failed_Verification_Failure]
How to Retry Retrofit Call on Http Errors (401) When Using Rxjava
Change Button Background At Runtime in Android
How to Set Up Android Studio to Work Completely Offline
How to Open Draw Overlay Permission Popup in Miui
Android Adb Doesn't See Device
Java.Io.Filenotfoundexception Open Failed Eacces (Permission Denied) on Device
How to Show a Video Thumbnail from a Video Path
Textview With Too Long Strings
Setting Onclicklistener for the Drawable Right of an Edittext