Reputation: 11
I am trying to start an activity that setup an email account from my main activity. Its not working and driving me nuts. What I have is:
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
EditText username = (EditText) findViewById(R.id.editText1);
EditText password = (EditText) findViewById(R.id.editText2);
ComponentName cname = new ComponentName("com.android.email",
"com.android.email.activity.setup.AccountSetupBasics");
Intent intent = new Intent("android.intent.action.MAIN");
intent.putExtra("com.android.email.AccountSetupBasics.username", username.getText().toString());
intent.putExtra("com.android.email.AccountSetupBasics.password", password.getText().toString());
intent.putExtra("com.android.email.extra.eas_flow", true);
intent.setComponent(cname);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
});
Manifest is:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.test.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And I always get this error:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.email/com.android.email.activity.setup.AccountSetupBasics}; have you declared this activity in your AndroidManifest.xml?
I'm new to this, who can tell me how to solve this error?
Any response is much appreciated.
Upvotes: 0
Views: 260
Reputation: 2042
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
EditText username = (EditText) findViewById(R.id.editText1);
EditText password = (EditText) findViewById(R.id.editText2);
ComponentName cname = new ComponentName("com.android.email",
"com.android.email.activity.setup.AccountSetupBasics");
Intent intent = new Intent(currentActivity.this, targetActvity.class);
intent.putExtra("com.android.email.AccountSetupBasics.username", username.getText().toString());
intent.putExtra("com.android.email.AccountSetupBasics.password", password.getText().toString());
intent.putExtra("com.android.email.extra.eas_flow", true);
intent.setComponent(cname);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
});
Upvotes: 0
Reputation: 75629
You can only start other's activity if it is exported. Check if com.android.email.activity.setup.AccountSetupBasics
is. And you should always do try/catch
as startActivity()
can throw exception for more reasons and if you will let it go uncaught, your app will crash
Upvotes: 1