Unable to start activity through intent: ActivityNotFoundException - android

I have this Activity defined in my AndroidManifest.xml:
<activity
android:name=".Splash"
android:label="#string/app_name"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I am trying to call it in this way:
Intent splashActivity = new Intent("android.intent.action.Splash");
mainAppContext.startActivity(splashActivity);
I get:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.Splash }
And when I try to start it in this way:
Intent splashActivity = new Intent("android.intent.action.MAIN ");
mainAppContext.startActivity(splashActivity);
It open a Complete action using dialog with many options there like play store etc.
Please help in starting this Activity.

From some other Activity:
startActivity(new Intent(this, Splash.class));

Intent splashActivity = new Intent("android.intent.action.Splash");
No-no-no! It should to
Intent splashActivity = new Intent(context, Splash.class);
If you use action - it seem that you want activity for some type of action, for example, view webpage on browser.
In your situation you have to use concrete activity and set it to intent
<action android:name="android.intent.action.MAIN" />
this action is not for your app, it is needed to android's launcher, that find activity in your application to launch it
Official documentation about intent mechanism

Where are you trying to launch this activity from? The following lines imply that Splash is your main Activity:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Are you trying to launch the Splash Activity from Splash itself? This would be problematic. If you are launching from another Activity then you can use the following to launch Splash:
Intent intent = new Intent();
intent.setClass(YourCurrentActivity.this, Splash.class);
startActivity(intent);

Activity not found exception is occurred when u are trying to use or start activity that is not declared into the Mainfeast.xml file.
And When you want to start any activity then you need to start that activity by using intent. but in android "android.intent.action.Splash" Intent Action exist. And you have declared the following intent filter
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
"android.intent.action.MAIN" this is the action name that indicate the this is the activity to be started first. and android send this intent and an activity that is registered with this intent action is the first activity to be started first.
So to start splash activity you doesn't need any intent. You just need to simply run this project. but If u want to Start Another activity from splash actiivty then u need to do following things.
Intent intent = new Intent(Context, ActivityName.class);
startActivity(intent);
or
startActivityForResult(intent, requestCode);
and remember that You have to declare that activity into the mainfeast.xml

Related

start activity without knowing its class

Is there a way to start an Activity without knowing its class, for example via an Intent Action?
The background is, I have two Modules, ModuleMain and ModulePushNotification. ModuleMain has a dependency to ModulePushNotification. From ModulePushNotification I want to start an Activity in ModuleMain, but I cannot add a dependency ModulePushNotification -> ModuleMain because this would produce a circular dependency.
Therefore, I cannot start the activity this way:
startActivity(new Intent(this, Main.class));
I tried to start the Activity using an Intent Action:
Intent intent = new Intent("com.android.main.MY_MAIN");
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(intent);
... with this Manifest in ModuleMain:
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.android.main.MY_MAIN" />
<category android:name="ANDROID.INTENT.CATEGORY.DEFAULT" />
</intent-filter>
</activity>
... but this produces the Exception:
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.main.MY_MAIN cat=[android.intent.category.DEFAULT]
Is there a way to start the main activity of the app, without restructuring the project/dependencies?
Try doing this way.
Intent intent = new Intent();
intent.setAction("com.android.main.MY_MAIN");
startActivity(intent);

Start Activity of Main project from my library project

I have 2 projects. One is my Main Project(A) , and another is a Library Project(B). I want to start an activity which is present in A from an activity which is located in B. How do I do that ?
I Tried startActivity(getApplicationContext(),B.class);
,but
B.class
is not resolved.
How Can I let my library project start an activity of my main project ?
You shouldn't need to use an intent filter. The code in Activity A can use
ComponentName cn = new ComponentName(this, "my.package.MyActivity.B");
Intent intent = new Intent().setComponent(cn);
startActivity(this, intent);
to specify the activity B should be started.
You can add custom Action in intent-filter of you activity and start that activity by specifying action
<activity android:name="my.package.MyActivity">
<intent-filter>
<action android:name="my.package.action.MY_ACTION"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="my.package"/>
</intent-filter>
</activity>
start activity with this code:
final Intent intent = new Intent("my.package.action.MY_ACTION");
intent.addCategory(getActivity().getPackageName());
startActivity(getActivity(), intent);

android how to start the main activity when I am on another activity

I am on signin activity and if the user click a button I want to start the main activity.
this is the mainfest for the main activity welcome
<activity
android:name=".Welcome"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I tried like this
Intent welcomeIntent =new Intent("android.intent.action.MAIN");
startActivity(welcomeIntent);
but i got a screen saying complete acting using with many choese , what is the solution pelase?
Change your intent to directly launch your class
Intent welcomeIntent = new Intent(context, Welcome.class);
startActivity(welcomeIntent);
If you're in an activity replace context with this

How to launch app at the same time on Android

I have two apps, A and B.
I want to call B by A.
My code in A is as below:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.example.bapp","com.example.bapp.BActivity"));
intent.putExtra ("test2abc", "abctest2");
startActivity(intent);
And B's intent filter in manifest as below:
<intent-filter>
<action android:name="ACTION_BACKCALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
But it will close B before launch B while B had opened.
I find below code to open *.txt file. This will open two txt reader app at the same time.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), mimetype);
startActivity(inte
nt);
How can I arrive that?
hey i found this code snippet Launch an application from another application on Android which will work for you
set the address of the application which you want to launch
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
you might want to try android:launchMode="singleInstance" and
android:finishOnTaskLaunch="true" while defining launcher activity.
<activity
android:name="com.example.test.sampleMediaPlayer"
android:label="#string/app_name"
android:launchMode="singleInstance"
android:finishOnTaskLaunch="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For Activity A.

Unable to launch an activity using implicit intent specifying only action

I am trying to launch an activity by specifying only its action(custom) defined in its intent filter from an activity in other application. The activity to be launched is the main activity of its application thus have android.intent.action.MAIN & android.intent.category.LAUNCHER set as action and category in its intent filter. Now according to android doc on Intent and Intent Filter, i do not need to specify DEFAULT category at all in this case. But doing the same i am i am unable to launch the activity.
LogCat says, Activity could not be found...
Am i misinterpreting the text or is there something else missing...?
Code, used for calling the activity
Intent i=new Intent();
i.setAction("android.AddressBookV4.firstActivity");
startActivity(i);
Definition of Activity being called in the manifest file
<activity android:name=".AddressBook"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.AddressBookV4.firstActivity" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You need to add the LAUNCHER category to your Intent, since the <intent-filter> says that it matches the following Intents (in pseudocode):
((action IS "android.AddressBookV4.firstActivity")
OR (action IS "android.intent.action.MAIN"))
AND (category IS "android.intent.category.LAUNCHER")

Categories

Resources