As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
Here is what I posted before. I had the same problem with IsUserLoggedIn() when the app starts up and it was because the build() function wasn't finished. You need a callback and check IsUserLoggedIn() in the build() callback. I used KinveyUserCallback.
Sorry for the delay. Here is the code I use in my global class. I only use getInitialClient at app startup to check if the display should go to the login view or the home screen.
public void getInitialClient(Context mainContext, int displayview) { mainActivityContext = mainContext; displayviewInt = displayview; client = new Client.Builder(this.getApplicationContext()).setRetrieveUserCallback(new KinveyUserCallback() { @Override public void onSuccess(User result) { Log.d(TAG, "Kinvey load complete. Load client user is: " + result.getUsername()); if (result.isUserLoggedIn()) { Log.d(TAG, "Kinvey user logged in - display home"); //code to display home screen } else { Log.d(TAG, "Kinvey user not logged in - display settings"); //code to display login screen } } @Override public void onFailure(Throwable error) { Log.d(TAG, "Kinvey Build failure"); } }).build(); }
Thanks for your answer Revillo, I took your advice about "Global class" you have half helped, how i can minimise and reopen an app and ".user().isUserLoggedIn()" returns true each time.
Success 1/2.
(Relevant) global application code looks like...:
package some.package.app; import android.app.Application; import com.kinvey.android.Client; public class AppApplication extends Application { private Client mKinveyClient; private static String APP_ID = "kid_ARandOm1D"; private static String APP_KEY = "xxxxxxxxxxxxxxxxxx"; @Override public void onCreate() { super.onCreate(); mKinveyClient = new Client.Builder(APP_ID,APP_KEY , this.getApplicationContext()).build(); } public Client getClient(){ return mKinveyClient; } }
Main Activity's oncreate looks like:
mKinvey = ((TechCheckApplication) getApplication()).getClient();
I have spend several hours and tried several ways to implement a call back onBuild() but am completely lost and only get compiler errors. are you able to provide a small snippet and or advise if the call back should be in the global class or the main activities variable which retrieves from the global class?
Kind Regards
I believe that is not configurable at this moment as the value is common across the board.
Another way to achieve this is to implement "Remember Me" checkbox option with login so that the user wouldn't need to enter the credentials again at the next login. This would mean saving the user's password locally using encryption.
Regards,
Wani
Hi Oliver,
As the android guide says, username and session is stored. This means that user's password is not stored but only that particular session information is stored.
And hence, you will need to call login method in only the following cases:
To specifically check the "logged in" status, you can use mKinveyClient.user().isUserLoggedIn().
And lastly, after successful registration, the user will be in logged in status for that application session and you will be able to check that by the same call - mKinveyClient.user().isUserLoggedIn().
Above information and relevant code snippets can be found at http://devcenter.kinvey.com/android/guides/users.
Let me know if you need anything else.
Regards,
Wani
Sagar,
If it's returning false when the application is killed it seems like the event thread is stuck for some reason (thread.sleep or otherwise). Can you refactor your code in a way that will be free of synchronous calls that hang the event thread?
Thanks,
The auth token expiry is set at 14 days.
Regards,
Wani
When you call thread.sleep() the thread will miss the reply if it comes in during those 5 seconds. Is there some reason why you're not using standard asynchronous programming paradigms that take advantage of threads and futures?
Thanks,
Hi Damien,
I have tried to perform the IsUserLoggedIn() check in the onSuccess() event of the Build function, the result is the same, once the application is killed it returns false.
I had the same issue at app startups and it was because the build() command wasn't finished before I called IsUserLoggedIn(). It was a pain because I had build() in the global class like the examples, but I needed to check user login in my main activity. However, you can use KinveyUserCallback for build() and check IsUserLoggedIn() in the callback function.
Hope this helps.
School boy error, the callback is a void method hence why it cant be assigned to a variable. but this has only solved half my problem, as long as the application is alive i.e. not terminated, the user remains logged in. but as soon as the application is terminated, the user is no longer logged in.
My Application code looks like:
package some.package.app; import android.app.Application; import android.content.Intent; import com.kinvey.android.Client; import com.kinvey.android.callback.KinveyClientBuilderCallback; public class AppApplication extends Application { public Client mKinveyClient = null; private static String APP_ID = "kid_xxxxxxxxxx"; private static String APP_KEY = "xxxxxxxxxxxxxxxxxxxxxxxx"; @Override public void onCreate() { super.onCreate(); new Client.Builder(APP_ID,APP_KEY, this.getApplicationContext()).build(new KinveyClientBuilderCallback() { @Override public void onSuccess(Client client) { mKinveyClient = client; } @Override public void onFailure(Throwable throwable) { } }); } public Client getClient(){ return mKinveyClient; } }
You will see in the above code that the mKinveyClient variable is initialised as "null" and I use the following Async to check if the the Client is initialized seems extreme but needed to be sure.
Client mKinvey; ... private class WaitForBuilder extends AsyncTask{ @Override protected void onPostExecute(Object o) { super.onPostExecute(o); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } mKinvey = ((TechCheckApplication) getApplication()).getClient(); if (mKinvey.user().isUserLoggedIn()){ Toast.makeText(getApplicationContext(), "LOGGED IN!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "LOGGED OUT!", Toast.LENGTH_LONG).show(); } } @Override protected Object doInBackground(Object[] params) { while (((TechCheckApplication) getApplication()).getClient() == null) { // Keep waiting... } return null; } }
I wait another 5 seconds after the Application class has assigned a value to the mKinveyClient variable to make sure it has initialised and yet IsUserLoggedIn() retruns false...
any help would be great on this one
Revilo
I’m able to login to my Kinvey account using the Android APIs, but I had some questions on how the login process works. The Android guide says the “library automatically cache’s the user’s name and a current authorization token in a saved credential store.” The first question I have is how long is the user information cached? I would prefer to not have to save the user’s password, but I don’t want them to have to login frequently.
The second question I have is what is the best way to check if a user is logged in? I didn’t see any API calls for login check.
The last question I have is do I need to make the user login again after they register?
Thanks for the time!