AccountAuthenticator.java:
Intent intent = new Intent(context, AccountActivity.class);
AccountActivity.java:
In onCreate(Bundle aBundle) I want to say:
getIntent().getContext();
But getContext() does not exist.
How do I get the Context from the Intent ?
Since it's passed in the Intent constructor, I was expecting it to be available on arrival in the AccountActivity.
Each object is given its own context, which contains the resources required to set that object up. It is required for many objects to be created, and to get program identifying information, among other purposes. This makes it invaluable to set up new views and activities, but it can also be used for other purposes.
context. startActivity(new Intent(context, ActivityClass. class)); This call to startActivity sends the Intent to the Android system, which is then in charge of creating and opening the activity that you have specified.
How do I get the Context from the Intent ?
You don't.
Since it's passed in the Intent constructor, I was expecting it to be available on arrival in the AccountActivity.
The Context
is only used to help create the Intent
routing information. Since an Intent
can (and frequently does) live outside of any Context
, an Intent
cannot hold onto a Context
.
I need the Service (i.e. Context) that created the Intent, so as to be able to create an AsyncTask taking it in the constructor.
You cannot do this, sorry.
If I don't do that I get: "java.lang.SecurityException: caller uid 10027 is different than the authenticator's uid", since the AsyncTask is doing Accountmanager am = Accountmanager.get(context).
This has nothing to do with AsyncTask
. This has to do with processes, not threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With