简体   繁体   中英

Android: execute method after returning to main activity from intent activity

I have seen many examples with

startActivityForResult(Intent, int)

and then using

onActivityResult(int, int, Intent) 

but for me I dont need to pass anything, I simply want to startActivity(intent), and when intent activity returns, a method get called in main activity.. Any tutorial on doing this?

EDIT: Here a sample code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_options);

    createEvent = (Button) findViewById(R.id.createEvent);
    createEvent.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(optionsInterface.this, MainActivity.class);
            startActivity(intent);
        }
    });
}

here, after I return from MainActivity (press back, or just close it), I want the activity to perform a task ( with no data being passed from MainActivity)

而不是startActivity()您可能需要使用startActivityForResult()使你得到一个回调的结果。

您可以使用startactivityforResult()..无论是否发送任何数据都没有关系...当您使用startactivityonResult()时,onActivityResult方法将被调用...只需检查请求代码,然后执行任何操作即可想要...发回一些东西是没有必要的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM