[android-developers] Re: onSaveInstanceState problem while making oAuth request
It sounds like the best solution for you is to bundle the row id in your intent's "extras" and then get it back during the callback. Check out http://developer.android.com/reference/android/content/Intent.html#putExtra(java.lang.String,%20int) and http://developer.android.com/reference/android/content/Intent.html#getIntExtra(java.lang.String,%20int) On Dec 12, 12:14 am, bobetko wrote: > In my app at some point I am making oAuth request to authorize user > with Twitter. App opens WebView in which user enter his credentials. > Upon user pressing "Allow" button, twitter sends Intent (which > contains token and secret) back to my app so user can start when he/ > she left of. The problem is my Activity has RowID (very important to > know which record is currently active) that get lost RowID is > parameter that my activity receives through Intent in onCreate event. > > I've checked, onSaveIstanceState is not executed, so when my Activity > gets control back, my RowID doesn't exist. > When my Activity receives Intent from Twitter, it is handled in > onResme event. I assume, here I should somehow obtain my RowID > What would be good way to remember my RowID and to be able to pull it > back? > > In my manifest I had to enter following for my Activity in order to be > able to get control back: > > android:name="android.intent.action.VIEW" /> > android:name="android.intent.category.DEFAULT" /> > android:name="android.intent.category.BROWSABLE" /> > android:host="oauth" /> > > > Any Suggestions. Thanks. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: onSaveInstanceState problem while making oAuth request
I think the approach you want to take here would be bundling 'extra's with your intent that you can read during the callback. Check out http://developer.android.com/reference/android/content/Intent.html#putExtra(java.lang.String,%20int) and http://developer.android.com/reference/android/content/Intent.html#getIntExtra(java.lang.String,%20int) for storing a rowid On Dec 12, 12:14 am, bobetko wrote: > In my app at some point I am making oAuth request to authorize user > with Twitter. App opens WebView in which user enter his credentials. > Upon user pressing "Allow" button, twitter sends Intent (which > contains token and secret) back to my app so user can start when he/ > she left of. The problem is my Activity has RowID (very important to > know which record is currently active) that get lost RowID is > parameter that my activity receives through Intent in onCreate event. > > I've checked, onSaveIstanceState is not executed, so when my Activity > gets control back, my RowID doesn't exist. > When my Activity receives Intent from Twitter, it is handled in > onResme event. I assume, here I should somehow obtain my RowID > What would be good way to remember my RowID and to be able to pull it > back? > > In my manifest I had to enter following for my Activity in order to be > able to get control back: > > android:name="android.intent.action.VIEW" /> > android:name="android.intent.category.DEFAULT" /> > android:name="android.intent.category.BROWSABLE" /> > android:host="oauth" /> > > > Any Suggestions. Thanks. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: onSaveInstanceState problem while making oAuth request
I haven't tried yet, but maybe you should see this: http://developer.android.com/guide/topics/resources/runtime-changes.html On Dec 12, 2:14 pm, bobetko wrote: > In my app at some point I am making oAuth request to authorize user > with Twitter. App opens WebView in which user enter his credentials. > Upon user pressing "Allow" button, twitter sends Intent (which > contains token and secret) back to my app so user can start when he/ > she left of. The problem is my Activity has RowID (very important to > know which record is currently active) that get lost RowID is > parameter that my activity receives through Intent in onCreate event. > > I've checked, onSaveIstanceState is not executed, so when my Activity > gets control back, my RowID doesn't exist. > When my Activity receives Intent from Twitter, it is handled in > onResme event. I assume, here I should somehow obtain my RowID > What would be good way to remember my RowID and to be able to pull it > back? > > In my manifest I had to enter following for my Activity in order to be > able to get control back: > > android:name="android.intent.action.VIEW" /> > android:name="android.intent.category.DEFAULT" /> > android:name="android.intent.category.BROWSABLE" /> > android:host="oauth" /> > > > Any Suggestions. Thanks. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: onSaveInstanceState problem while making oAuth request
It is unlikely this has anything to do with saving and restoring instance state, unless a configuration change is happening or your process is being killed in the background. If you are saying that you are seeing onCreate() called, then again I think you should consider that you actually have a new instance of the activity being started, and look at the logcat output if there is a log about starting an activity. On Sun, Dec 12, 2010 at 9:02 AM, bobetko wrote: > Sorry. Yes. You are right. onCreate runs first, then onResume next. (I > am still learning about Android activity cycle :-) > Here is my onResume method that handle this data that comes from > Twitter. > See lines 5 and 6. If 6 is true I am extracting token and secret and > saving them to SharedPreferences. This code runs fine, just that RowID > variable gets lost in the process. onCreate that runs before this one > (onResume), has no idea about RowID. > > @Override > protected void onResume() { >super.onResume(); >Log.d(TAG, "mRowID onResume : " + mRowId); >Uri uri = this.getIntent().getData(); >if (uri != null && uri.toString().startsWith(CALLBACK_URL)) { >SessionPilot appState = > ((SessionPilot)getApplicationContext()); >consumer = appState.getConsumer(); >provider = appState.getProvider(); >String verifier = > uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER); >try { >provider.retrieveAccessToken(consumer, verifier); >Utils.StoreStringToPrefs("twitterToken", > consumer.getToken(), PREF_FILE_NAME ,this); >Utils.StoreStringToPrefs("twitterSecret", > consumer.getTokenSecret(), PREF_FILE_NAME ,this); >} catch (Exception e) { >Log.e(APP, e.getMessage()); >} >} > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: onSaveInstanceState problem while making oAuth request
Sorry. Yes. You are right. onCreate runs first, then onResume next. (I am still learning about Android activity cycle :-) Here is my onResume method that handle this data that comes from Twitter. See lines 5 and 6. If 6 is true I am extracting token and secret and saving them to SharedPreferences. This code runs fine, just that RowID variable gets lost in the process. onCreate that runs before this one (onResume), has no idea about RowID. @Override protected void onResume() { super.onResume(); Log.d(TAG, "mRowID onResume : " + mRowId); Uri uri = this.getIntent().getData(); if (uri != null && uri.toString().startsWith(CALLBACK_URL)) { SessionPilot appState = ((SessionPilot)getApplicationContext()); consumer = appState.getConsumer(); provider = appState.getProvider(); String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER); try { provider.retrieveAccessToken(consumer, verifier); Utils.StoreStringToPrefs("twitterToken", consumer.getToken(), PREF_FILE_NAME ,this); Utils.StoreStringToPrefs("twitterSecret", consumer.getTokenSecret(), PREF_FILE_NAME ,this); } catch (Exception e) { Log.e(APP, e.getMessage()); } } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: onSaveInstanceState problem while making oAuth request
"onResume runs first then onCreate" -- that is not typical. Either your activity is being restarted (due to a configuration change) or you have a new instance created. Also what do you mean by "Twitter sends Intent (with token and secret) back to my activity"? Do you mean it is using setResult()? Or is this doing something else? And do please have a look at the logcat output to see what activities are being started. On Sun, Dec 12, 2010 at 8:18 AM, bobetko wrote: > Thanks Dianne, > > I've look at logs and my app is crashing because my RowID value is > null. RowID is record ID that is needed to query sqlite database. > I could post here all my code, but I doubt it would be very useful... > I'll try explaining better with some code snippets: > > This is what I execute when user push Authorize button: > > consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, > CONSUMER_SECRET); > provider = new DefaultOAuthProvider("http://twitter.com/oauth/ > request_token", > "http://twitter.com/oauth/access_token";, > "http://twitter.com/oauth/authorize";); > String authUrl = provider.retrieveRequestToken(consumer, > CALLBACK_URL); > mWebView.loadUrl(authUrl); > > User is presented with login and password fields and there is also > Allow button. When user pushes this Allow button, Twitter sends Intent > (with token and secret) back to my activity. I process this Intent in > onResume method. OnResume runs first, then onCreate. At this point my > RowID is lost. Nowhere in this process onSaveInstanceState was called > because of simple reason, activity is not paused, exited, screen is > not rotated, etc... So, how do I save and retrieve my RowID? Thanks. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: onSaveInstanceState problem while making oAuth request
Thanks Dianne, I've look at logs and my app is crashing because my RowID value is null. RowID is record ID that is needed to query sqlite database. I could post here all my code, but I doubt it would be very useful... I'll try explaining better with some code snippets: This is what I execute when user push Authorize button: consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); provider = new DefaultOAuthProvider("http://twitter.com/oauth/ request_token", "http://twitter.com/oauth/access_token";, "http://twitter.com/oauth/authorize";); String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL); mWebView.loadUrl(authUrl); User is presented with login and password fields and there is also Allow button. When user pushes this Allow button, Twitter sends Intent (with token and secret) back to my activity. I process this Intent in onResume method. OnResume runs first, then onCreate. At this point my RowID is lost. Nowhere in this process onSaveInstanceState was called because of simple reason, activity is not paused, exited, screen is not rotated, etc... So, how do I save and retrieve my RowID? Thanks. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: onSaveInstanceState problem while making oAuth request
I thought about that. But, then another question come to my mind. Why wouldn't I always use SharedPreferences to save my activity state? For example: I passed groupID and itemID values into activity. In onCreate, I save both values to SharedPreferences. Latter, when activity is restarted (for any reason: rotation, pause, was destroyed, etc.), I check Intent first, if nothing is passed, I load values from SharedPreferences. This way I woulnd't have to use onSaveInstanceState ever. Is this OK to do? Thanks a lot. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en