Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

Android Studio Java - looking solution to reset Previous Activity in passed activity

Assume I have 2 activities called "ActivitiyA" and "ActivitiyB".

I have an intent that enables me to go "activityB" from "activityA". In one of the function in "activityB" will be called "finish()" to send the user back to "ActivityA". Before showing activity A, I would like to reset 2 EditText from "ActivityA".

In order to satisfy above scenario what should I do?

Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In ActivityA, launch ActivityB for result using startActivityForResult and check for onActivityResult to clear edittext

val REQUEST_CODE = 1234
startActivityForResult(Intent(this, ActivityB::class.java), REQUEST_CODE)

override fun onActivityResult(requestCode: Int, resultCode : Int, data: Intent){  
     super.onActivityResult(requestCode, resultCode, data)
     if(requestCode == REQUEST_CODE) {  
         //clear or reset edittext here
     }  
} 

In ActivityB, before finishing do below

setResult(1234, Intent())
finish()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...