Launch Activity from another Application Module - android

How can I launch an Activity from another Application Module within the same project?
I am not talking about how to open an Activity from another application, therefore this is not a duplicate of Launch an application from another application on Android
I have 2 modules: mobile and tv. Both are com.android.application on their build.gradle files and both are on the same package com.example.myapp.
I want the tv module to launch the MainActivity of the mobile module.
I've added the following line to my build.gradle(tv) file:
compile project(path: ':mobile')
on MainTvActivity.java I tried to reference the MainActivity
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
which didn't work, because it couldn't resolve the symbol MainActivity. It won't even build.
The other attempt was to use intent filters:
on AndroidManifest.xml(mobile)
<activity
android:name="com.example.myapp.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.example.myapp.mobile" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
on MainTvActivity.java:
Intent intent = new Intent("com.example.myapp.mobile");
startActivity(intent);
which will build and install but will crash because it won't find anything to resolve the intent. However, if I install the mobile version and then run the tv one, it will work (as expected).

Related

Instant App postInstallIntent crashes because Activity Fails resolution

I have an onClickListener() for a Download button in the sole activity in my Instant App package. When clicked, it forms the postInstallIntent:
Intent postInstallIntent = new Intent(getApplicationContext(), Test.class);
When I Run instantapp, it crashes at this line with this Logcat entry:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/quixr/testqiew2/full/Test;
The activity Test is in the feature module full and is a Launcher:
<application>
<activity android:name=".Test">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
The build.gradle for app contains a dependency on full:
implementation project(':full')
Should Test be somewhere else to be found? Or is there a different reason it is not being found?

cannot deal with dependencies in Android Studio

I have 2 project (A and B) A is the sdk and the other is an application that uses sdk.
I want to join A to B with gradle and i don't know how.
Thanks
you need to show a new MainActivity instance you need to declare an intent-filter in your project B manifest:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="your.package.here.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />

Cannot Launch Activity in Android Library Module

To my Android app project, I added a module which contains an activity named "SampleDataMenuActivity". There is nothing special to this activity - it's added using the "New Module" -> "Android Library" dialog in Android Studio and includes the "Hello World" code generated by Android Studio.
The AndroidManifest.xml of the app includes (from the module):
<activity
android:name="com.sample.sampledata.SampleDataMenuActivity" >
<intent-filter>
<action android:name="android.intent.action.SampleDataMenuActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
In the build.gradle of the app:
dependencies {
(...)
compile project(':sampledata')
}
In the settings.gradle of the project:
include ':sampledata', ':app'
In the main activity of my app, I want to navigate to an activity in the module using:
startActivity(new Intent("com.sample.sampledata.SampleDataMenuActivity"));
The project builds just fine, but when I tap the button that should take me to the activity in the module it fails, reporting:
android.content.ActivityNoFoundException: No Activity found to handle Intent ( act=com.sample.sampledata.SampleDataMenuActivity )
What did I miss?
I found the mistake, and perhaps I should remove the question. But as it was upvoted, somone else might be interested in this answer:
The manifest should state:
<activity
android:name="com.sample.sampledata.SampleDataMenuActivity" >
<intent-filter>
<action android:name="com.sample.sampledata.SampleDataMenuActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

no launcher activity found smartatch

I'm trying to run sample for Sony site.
I attached SmartExtensionAPI and SmartExtensionUtils. I used Properties->Android->Library and checked is library.
When I ran a sample (for example HelloWidget) on Eclipse, I get this error on the console:
HelloWidget] No Launcher activity found!
HelloWidget] The launch will only sync the application package on the device!
But the installation is done... I can see the application is installed on my smartphone and I can see too on SmartConnect but not in the smartwatch.
Does anyone have an idea of what I'm doing wrong ?
EDIT:
AndroidManifest.xml
<activity android:name="com.example.sonymobile.smartextension.hellowidget.HelloWidgetPreferenceActivity"
android:label="#string/preference_activity_title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This is because no activity had set as a launcher to run when app is launched
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
no intent filter will be there in the code's manifest, just check it.

No Launcher activity found, The launch will only sync the application package on the device

I got this warning from console when running my application on emulator
No Launcher activity found!
The launch will only sync the application package on the device!
In fact i have declared an activity as the main launcer in AndroidManifest.xml file
<activity
android:name=".myActivity"
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 don't need any other intent-filter to use on that activity.. just basic main and launcher
What's the reason? Please give me a solution..
If the launcher activity is in another package, you will need to specify that as well.
For instance, from one of my personal projects:
<activity
android:name=".activities.MainScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The MainScreen.java is in the activities package. Also, check spelling for upper or lower case letters.
It seems that you must have "android.intent.action.MAIN" specified immediately before "android.intent.category.LAUNCHER". I encountered the same issue as you when I had the following:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
The issue was resolved only when I re-orderd as follows:
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
In all normal circumstances, listen to what the other guy(s) said.
I was able to replicate your issue using a Mac Book Pro & Eclipse Indigo. when you create your android project, you MUST have Eclipse start you off with a templated activity (like a blank activity). if you don't, and you try to add an activity to your manifest later, Eclipse just derps and can't find the launcher. (i looked at other manifest files and i can't see any differences. i really don't think it's your poor manifest's fault in this special case.)
here's your lazy easy fix:
start a new project, and copy over all the files (make sure you back up ur files first, in case you delete something wrong or mess up the ordering)
Using Eclipse Indigo, open Run Configurations windows, click the project and use launch default activity on Android tab, choose Automatically pick compatible device...and apply.

Categories

Resources