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.
Related
I have two android apps(i.e. BIApp and EApp) and I am trying to open EApp from BIApp.
EApp has two activity one is MainActivity and another is LandingPageActivity.
When I try to launch MainActivity using startActivity(intent) it works fine but if I try to launch LandingPageActivity. startActivity(intent) does nothing.
if EApp is open in background then startActivity(intent) works for LandingPageActivity too.
Below is the code snippet that I am using.
Intent intent = new Intent();
intent.setClassName("com.pkg.eapp", "com.pkg.eapp.LandingPageActivity");
startActivity(intent);
I want to start LandingPageActivity.
What should I do ?
Try this:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.pkg.eapp", "com.pkg.eapp.LandingPageActivity"));
startActivity(intent);
and add
android:exported="true"
and in the intent-filter add
<category android:name="android.intent.category.DEFAULT"/>
to the declaration of LandingPageActivity in the manifest.
Try this, this is working for me
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.pkg.eapp", "com.pkg.eapp.LandingPageActivity"));
startActivity(intent);
Read how to allow Other Apps to Start Your Activity
You only need to add android.intent.category.DEFAULT category to your Activity onto manifest. Like below
<activity android:name="com.pkg.eapp.LandingPageActivity">
<intent-filter>
<action android:name="com.pkg.eapp.action.OPEN_LANDING_PAGE" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
and call it as
Intent intent = new Intent("com.pkg.eapp.action.OPEN_LANDING_PAGE");
intent.setComponent(new ComponentName("com.pkg.eapp", "com.pkg.eapp.LandingPageActivity"));
// Or intent.setPackage("com.pkg.eapp");
startActivity(intent);
I have never done this but may be LandindPageActivity is not accessible by other apps. In your EApp manifest, do you have an intent filter like this for the LandingPageActivity ?
<intent-filter>
<action android:name="com.pkg.eapp.LandingPageActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Try this:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.pkg.eapp.LandingPageActivity");
startActivity(LaunchIntent);
Hope this might help you.
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
I'm using this code to refresh MainActivity.java when a Refresh button is pressed.
Intent intent = getIntent();
finish();
startActivity(intent);
MainActivity.java has the category default and there is another Launcher activity. So whenever I press the Refresh button the Launcher Activity also starts again. I only need to start the MainActivity class. Below is the manifest
<application
android:allowBackup="true"
android:icon="#drawable/play_icon"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
<activity
android:name="com.theanilpaudel.joshilo.FirstScreen"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.theanilpaudel.joshilo.MainActivity"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
What you are looking for in this case is an explicit Intent that launches MainActivity.
You can do this like so:
Intent mainIntent = new Intent(this, MainActivity.class);
startActivity(mainIntent);
This will ensure that the Intent only launches MainActivity.
However, I highly recommend re-evaluating why you need to completely restart the Activity to refresh it. There are much cheaper (faster and less resource intensive) methods of updating data displayed in an Activity.
I guess I know the culprit. Try using the following code once.
Intent intent = getIntent();
startActivity(intent);
finish();
As far as I know startActivity() uses context to run. In case if you call finish() before startActivity() that may lead to destroy context of MainActivity and will get the application's context i.e. fires the activity with behavior LAUNCHER or MAIN.
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Let me know if it helps or you still have difficulty reloading activity.
Cheers
I would like to launch, from my app, two specific activities A_Activity and B_Activity from apps Aapp and Bapp
I inserted two buttons and in the two OnClickListener I wrote
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("com.Acompany.Aapp.A_Activity");
ctx.startActivity(intent);
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("com.Bcompany.Bapp.B_Activity");
ctx.startActivity(intent);
Moreover I added to AndroidManifest.xml the following lines
<activity
android:name="com.Acompany.Aapp.A_Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Acompany.Aapp.A_Activity" />
</intent-filter>
</activity>
<activity
android:name="com.Bcompany.Bapp.B_Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Bcompany.Bapp.B_Activity" />
</intent-filter>
</activity>
But my app crashes and in the logcat I read "No Activity found to handle Intent"
Where is my mistake?
EDIT: More precisely the two activities are not in my own app
More precisely the two activities are not in my own app
You should investigate target app's manifest file first, to check if these activities are available to others by being exported or offering publicly accessible intent filters. It looks you may simply be not allowed to do what you attempt to.
Try like this. For your home activity(first launch activity) do like this in your manifest file.xml
<activity
android:name="com.Acompany.LaunchHomeActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.Acompany.LaunchHomeActivity" />
</intent-filter>
</activity>
<activity android:name="com.Acompany.Aapp.A_Activity">
</activity>
<activity android:name="com.Bcompany.Bapp.B_Activity">
</activity>
don't include <intent-filter> to all activities
Intent intent = new Intent(myFirstClass.this, MySecondClassA.class);
startActivity(intent);
Class B
Intent intent = new Intent(myFirstClass.this, MySecondClassB.class);
startActivity(intent);
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