在登录屏幕上使用改进从服务器调用数据,并希望显示其他活动的数据

问题描述 投票:0回答:1

我正在使用改造库我想在登录屏幕上调用所有数据,如果登录成功,则通过相同的getter setter在下一个活动中显示数据。这可能吗?

public void onResponse(Call<TaskResponse> call, Response<TaskResponse> response) 
{
    int statusCode = response.code();
    String checking = String.valueOf(response.body().getCode());
    if (checking.equals("0"))
        Toast.makeText(getApplicationContext(),"Invalid username or Password",Toast.LENGTH_LONG).show();
    else if (checking.equals("2"))
        Toast.makeText(getApplicationContext(),"Invalid Company Code",Toast.LENGTH_LONG).show();
    else if (checking.equals("1")) {
        Toast.makeText(getApplicationContext(), "Login Successful", Toast.LENGTH_SHORT).show();

        List<Task> test;
        test = new ArrayList<Task>();
        test = response.body().getTasks();

        Intent intent = new Intent(LoginActivity.this, EmpTaskActivity.class);
        intent.putParcelableArrayListExtra("test", (ArrayList<? extends Parcelable>) test);
        startActivity(intent);
    }

   //  recyclerView.setAdapter(new MoviesAdapter(movies, R.layout.list_item_movie, getApplicationContext()));
}
android android-studio retrofit retrofit2 getter-setter
1个回答
1
投票

登录成功时(在您的LoginActivity中)。

Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra("DESIRE_KEY",loginModelUsedToCallRetrofitAPI);
startActivity(intent);

并在MainActivity(成功登录后要调用的第二个活动)

Intent intent = getIntent();
LoginModelUsedToCallRetrofitAPI loginModelUsedToCallRetrofitAPI = intent.getSerializableExtra("DESIRE_KEY");

这应该做你想要的!

© www.soinside.com 2019 - 2024. All rights reserved.