I have tried the approach below to automatically login current User. But onDestroy, User still has to login
public class LoginActivity extends AppCompatActivity {
private Client client;
private Account account;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
client = new Client();
client.setEndpoint("https://[HOSTNAME_OR_IP]/v1");
client.setProject("[PROJECT_ID]");
client.setKey("[API_KEY]");
account = new Account(client);
}
@Override
protected void onResume() {
super.onResume();
try {
account.get(new CoroutineCallback<>(
(result, error) -> {
if (error != null)
error.printStackTrace();
return;
}
));
// User is logged in
} catch (AppwriteException e) {
// User is not logged in
}
}
}
What exactly happens when this is executed? It doesn't look like you're doing anything with the result of account.get() sooooo 🧐
@Override
protected void onResume() {
super.onResume();
AppwriteClient appwriteClient = new AppwriteClient(getApplicationContext());
Account account = appwriteClient.getAccount();
try {
account.get(new CoroutineCallback<>(
(result, error) -> {
if (result != null)
startActivity(new Intent(LoginActivity.this, MainActivity.class));
Log.d("appwrite", "onResume:result " + result);
}
));
} catch (AppwriteException e) {
e.printStackTrace();
finish();
}
}
@Steven sorry for late reply. I have added a navigation so mainFragment. But i still get the same result. It lunches the loginActivity before navigating
So the onResume is being logged?
Yes, When they is an active Session, But the problem is when onResume loginActivity appears for atleast 1.5 sec before navigating to Mainfragment
sorry i don't understand. also, what is the result that's logged?
The log shows the user in active session. But my concern is the delay before resuming active session
What do you mean?
Recommended threads
- {"code": 1008, "message": "Invalid Origi...
Nothing has changed in my application or console settings so I'm curious as to what I need to do to fix this. I already have the client registered so I'm not en...
- android platform invaild origina
It happened today suddenly. Our app says invalid origin. And appwrite cloud says every time we tried to add the app to it: "param platformId" is not optional.
- All my apps are not opening now
All my apps are not opening now 200+ apps are not opening plz fast