i have got an controller which is inherited by application, i have also set it in manifest file. now i want to call a activity from here. i'm not getting how to do?
Here how i'm trying, but it fails
public class SampleApplication extends android.app.Application {
public SampleApplication() {
// TODO Auto-generated constructor stub
Context context = SampleApplication.this.getApplicationContext();
Intent intent = new Intent();
intent.setClass(context, MainActivity.class);
startActivity(intent);
}
My manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sampleapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name="SampleApplication"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.sampleapp.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>
</manifest>
You can do what you are trying to do by simply using the AndroidManifest.xml file :
<activity android:name="Activity name" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Related
This question already has answers here:
What does it mean "No Launcher activity found!"
(17 answers)
Closed 8 years ago.
I'm getting something that looks like this:
"No Launcher activity found!
The launch will only sync the application package on the device!"
I'm not sure how to fix this. My AndroidManifest looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</application>
</manifest>
Any help would be greatly appreciated. Thanks!
You need to add the activity to your manifest. For example, if your initial activity is called MainActivity:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.helloworld.MainActivity"
android:label="Main Activity!" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Edit: The above shows an activity that is also being used as a launcher. Here is an example of a regular activity also being added to the manifest.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.helloworld.MainActivity"
android:label="Main Activity!" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.helloworld.SecondActivity"
android:label="My second activity"
android:parentActivityName="com.example.helloworld.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.helloworld.MainActivity" />
</activity>
</application>
You should add your acivities to the manifest file.
For Example:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="<Package><ClassName>"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</applicaion>
Whenever you create Android Project in Eclipse it automatically generates a class called MainActivity which extends activity and generates Manifest file for you with a default entry of your MainActivity. Whenever you create a new class that extends Activity then you have to manually enter your activity in your manifest. You can change your your intent filter any time and you can set it to any activity and that activity will be your launcher activity of the app. This is a default Manifest file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<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>
</manifest>
So most responses told me to check that there's an activity with the category set to LAUNCHER. I have 2 activities - one starting the other, and 2 .xml layout files (for each of the activities)- I get the "No Launcher activity found" when trying to run on emulator.
This is my manifest-file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.orbliners.workout"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="dk.orbliners.workout.MainActivity" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="SecondaryActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="dk.orbliners.workout.SecondaryActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
For your main activity you need something like this:
<activity
android:name="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>
I have a BootUpReceiver class which I'm attempting to use with RECEIVE_BOOT_COMPLETED to launch an Activity when the device boots. The problem is - it does not seem to do so when I launch the app then restart the device.
I have verified there is no issue running Activity1.java - the issue lies either in the Manifest or the BootUpReceiver class but I'm not sure exactly why it will not launch after rebooting.
BootUpReceiver.java:
public class BootUpReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, Activity1.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.com.idg.voiscphone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.idg.voiscphone.Activity1"
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.idg.voiscphone.Activity2"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.idg.voiscphone.Activity3"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.idg.voiscphone.Activity3a"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.idg.voiscphone.Activity3b"
android:label="#string/app_name" >
</activity>
<receiver android:enabled="true" android:name=".BootUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
Example Source:
http://androidrocksonmobility.blogspot.com/2012/01/how-to-create-auto-start-android.html
Remove android:permission="android.permission.RECEIVE_BOOT_COMPLETED" and try again.
Beyond that, there is no requirement that your activity appear in front of any other activity that might be started around the same time, such as the home screen.
In this app I want a button press to open a different Java file now I have done this many times before but I can't seem to get it to work now. i was just wondering if anyone can see what i have done wrong
this is my manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ucas.course"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SQLView"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.SQLVIEW" />
<category android:name="android.intent.category.OTHER" />
</intent-filter>
</activity>
</application>
</manifest>
and this is how I start the intent
public void onClick(View v) {
if(v.getId() == R.id.button1) {
Intent temp = new Intent("android.intent.action.SQLVIEW");
startActivity(temp);
}
}
There is no android.intent.category.OTHER, you probably meant android.intent.category.DEFAULT.
the purpose of this activity/program is to simply switch from this activity to another one using a button. From IzzynActivity to notes. Here is the android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="izzy.n"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="izzy.n.IzzynActivity"
android:label="#string/app_name" >
<activity
android:name="izzy.n.notes"
android:label="#string/notes"></activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here is the IzzynActivity.java code:
package izzy.n;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class IzzynActivity extends Activity{
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button wg = (Button) findViewById(R.id.button1);
wg.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(IzzynActivity.this, notes.class);
IzzynActivity.this.startActivity(myIntent);
}
});
}
}
An activity cannot contain another activity in the AndroidManifest.xml file. Here's the right code:
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="izzy.n.IzzynActivity"
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="izzy.n.notes"
android:label="#string/notes"></activity>
</application>
</manifest>
Note:
If you return anything with setResult() from a started activity you should start it using startActivityForResult.
For the warning message:
Just edit one piece of code and re-run your application. It will be reinstalled on the phone and you should not see the warning message again.
For one you have an activity tag inside another activity tag in your manifest which is clearly wrong.
Change your manifest to this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="izzy.n"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".IzzynActivity"
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=".notes"
android:label="#string/notes">
</activity>
</application>
</manifest>
<activity
android:name="izzy.n.IzzynActivity"
android:label="#string/app_name" >
<activity
android:name="izzy.n.notes"
android:label="#string/notes"></activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
you are declareing an activity inside another activity without closing first one: so replace this block with:
<activity
android:name="izzy.n.IzzynActivity"
android:label="#string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="izzy.n.notes"
android:label="#string/notes"></activity>
<intent-filter>
</activity> closing tag for your first activity should come before starting tag for your second activity. You are nesting your activities, which is not permitted.