开发者

good practice using finish()

I'm really new to android and I've created an app t开发者_Python百科hat has buttons which lead to other activities where data is selected to be sent back to the main activity by an intent with extras.

When I'm done with the data gathering activity I call the finish() method to return back to my main activity.

The user may wish to revisit the information gathering activity to enter new data but it doesn't matter if the previously entered data is not there when they return to the activity.

is this considered to be good or bad practice when writing an app?

Thanks, M


Depends on your application.

If your application need a permament data like a options activity or a date enter activity you must to "save" the changes of your activity. There are a a easy form to do that with the Overryde methods:

/**
 * Method onSaveInstanceState.
 * @param outState Bundle
 */
@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putBoolean("ISCALLSMS", isOnCallingSms);
    super.onSaveInstanceState(outState);
}


/**
 * Method onRestoreInstanceState.
 * @param savedInstanceState Bundle
 */
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    if ( (savedInstanceState != null) && (savedInstanceState.containsKey("ISCALLSMS")) ){
        isOnCallingSms = savedInstanceState.getBoolean("ISCALLSMS");
    }
    super.onRestoreInstanceState(savedInstanceState);
}    

*This are a example of my app. Yoy should decide what data you need to save. There are other methods to save your data, this is only one of them.

In other case, if your app dont need to save data its ok how you finish your activity

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜