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
- OAuth Missing redirect URL
Hello all, on a Flutter mobile app with latest Appwrite dependency (25.4.0) I always got "Missing redirect URL" - "Your OAuth login flow is missing a proper red...
- Need Help on Self Hosted Version of Appw...
Hi i wanted to test SMS OTP verify method but i am not able to do it. I follow all the steps but no luck. Please help me with this. I am using Appwrite self hos...
- Appwrite rejecting create and edit reque...
hello, so my issue is that when i make a debug build of my app, everything works as it should, but when i download and test a SIGNED release database rejects al...