Passing custom objects between activities?

前端 未结 5 1256
忘掉有多难
忘掉有多难 2020-12-03 17:43

How do I pass custom objects between activites in android? I\'m aware of bundles but I can\'t seem to see any functionality for this in them. Could anyone show me a nice exa

5条回答
  •  無奈伤痛
    2020-12-03 18:46

    Given an object PasswordState that implements Serializable throughout the object tree, you can pass this object to anther activity as in:

    private void launchManagePassword() {
        Intent i= new Intent(this, ManagePassword.class); // no param constructor
        PasswordState outState= new PasswordState(lengthKey,timeExpire,isValidKey,timeoutType,"",model.getIsHashPassword());
        Bundle b= new Bundle();
        b.putSerializable("jalcomputing.confusetext.PasswordState", outState);
        i.putExtras(b);
        startActivityForResult(i,REQUEST_MANAGE_PASSWORD); // used for callback
    }
    

提交回复
热议问题