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
- Deep Linking & Password reset
I am using react native with expo. I want to implement deep link with the url recived via email. So when clicked the link it opens my app. I havent ever used de...
- custom domain with CloudFlare
Hi all, it seems that CloudFlare has blocked cross-domain CNAME link which made my app hostname which is in CloudFlare, unable to create a CNAME pointing to clo...
- My organization's project is blocked
My organization's project is blocked so unblocked my organization then I will this