I have a problem with tabhost widget. I have some activities in tabs which are working fine. When I want to open a new activity from inside one of the tabs, runtime gives me the
Instrumentation.checkStartActivityResult(int, Object) line: 1504
ActivityNotFoundException
I put the activity in the manifest file and it's ok(I can run it if i put it in a tab). But when i try to fire the activity from another activity which is currently in one of the tabs, it get this exception. Any help is appreciated.
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".CoaActivity"
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=".MainMenu"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
<activity android:name=".favorites"></activity>
<activity android:name=".FoodMenu"></activity>
<activity android:name=".Info"></activity>
<activity android:name=".Restaurants"></activity>
<activity android:name=".Home"></activity>
<activity android:name=".RestaurantInfo"></activity>
</application>
favorites, foodmenu, info, restaurants, home have their own tabs. But restaurant info doesnt have its own tab. And when i try to run restaurant info by an intent I have the exception.
I found a solution for my problem. You have to use a ActivityGroup object, that fires other Intent objects. There is a little bit tutorial here : http://united-coders.com/nico-heid/use-android-activitygroup-within-tabhost-to-show-different-activity. Hope it helps..
Related
I have pasted the code of my Androidmanifest.xml,how does android decides which activity to launch when application starts ? In this case its the mainactivity. What changes to I need to make if I want to launch AnotherActivity when application launches?
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.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>
<activity
android:name="com.example.AnotherActivity"
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>
The MAIN element specifies that this is the "main" entry point to the application. The LAUNCHER element specifies that this activity should be listed in the system's application launcher (to allow users to launch this activity).
<activity
android:name="com.example.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>
Just remove the intent filter from the next activity!!
When the user selects your app icon from the Home screen, the system calls the onCreate() method for the Activity in your app that you've declared to be the "launcher" (or "main") activity. This is the activity that serves as the main entry point to your app's user interface.
You can define which activity to use as the main activity in the Android manifest file, AndroidManifest.xml, which is at the root of your project directory.
The main activity for your app must be declared in the manifest with an that includes the MAIN action and LAUNCHER category. For example:
<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>
Based on this, we can conclude that you currently have a faulty configuration. Only one activity can have the Intent filter for Main (so you should remove the <intent-filter> from your .MainActivity if you want to use AnotherActivity as you "Home" Activity).
<activity
android:name="com.example.AnotherActivity"
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="MainActivity" ></activity>
As stated in our conversation, you want to show a determinate action at launch, with is own functions and layout. The solution is to use one Activity which inflate Fragment1 or Fragment2, based on your condition.
Dealing with Fragment is very difficult, but when you will master them, you will have fun. There are few example on the net about Fragment, but i tell you this: read and practice is the only way you will learn something. Copy and paste from other source code / example will not help you. Follow this links:
link 1
link 2 with sample
link 3 for supporting tablets
Good luck!
I make android application with two layouts, when I export project, and install it on phone and tablet I got two icons in menu, first open main layout, when I start second icon it open second layout
Is problem in layout calling, I make two classes for layout.
How I can solve this? thanx
You just need to call new activity ..
Intent intent = new Intent(YourCurrentActivity.this, NewActivityToOpen.class);
startActivity(intent);
Also don't forgot to define same over AndroidManifest.xml .. :)
<application ...>
<activity android:name=".YourCurrentActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NewActivityToOpen" />
You may need to put the fully qualified java classname to android:name.
Problem in manifest file.
When you declare activity u sign all activity with
<intent-filter>
<action android:name="android.intent.action.MAIN"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="landscape"
/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
But this code using only for first activity^ next must declare only like:
<activity
android:name=".YourClass"
android:label="#string/app_name"
>
</activity>
I am very new to android development with eclipse, and I encounter dozen of errors and problems. Here is the next one:
I am following an android tutorial given here in order to set up the action bar. In this tutorial is says to insert an activity as follows:
<activity android:theme="#style/Theme.AppCompat.Light" ... >
Can I just put this line into the xml manifest file?
<activity android:theme="#style/Theme.AppCompat.Light">
Or do I need to replace the '...' by something more useful?
Please read the docs: activity-element
The activity's name is required, so you would need to have:
<activity android:theme="#style/Theme.AppCompat.Light" android:name="MyActivity">
Other than that, you are not required to add any other attributes.
Although be sure to place the activity element within the proper place in your xml. It should be contained in your application block:
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.Holo.Light">
<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>
</application>
Unless you really want your app to work under API levels under 3.0 then you have to add it like this.
android:theme="#style/Theme.AppCompat.Light"
Inside your already defined activity in your manifest (the one that has the intent filter and other declarations).
otherwise you dont have to add that at all.
This is one example.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light"
android:screenOrientation="portrait"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and this is another
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme=#style/Theme.AppCompat.Light"" >
<activity android:name=".DetailActivity"
android:label="#string/app_name" >
</activity>
The second way you posted is just fine, be sure to close the activity tag so it looks like <activity android:theme="#style/Theme.AppCompat.Light"></activity>
Also, if you're using eclipse, it is easier to go into the AndroidManifest and under the Application tab scroll to the bottom where there's Application Nodes and then add your view from there. Eclipse will auto generate the correct code in the xml file.
I am trying to learn Android.
I simply have Splash.Java and MainActivity.Java classes.
Before Splash.Java was the starting Action of my application.
Now I want to change it to MainActivity.Java.
Here is what I have done:
<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=".Splash" android:label="#string/title_activity_main">
<intent-filter>
<action android:name="com.example.anddappp.SPLASH" />
<category android:name="com.example.anddappp.DEFAULT" />
</intent-filter>
</activity>
</application>
I cleaned my Project, and I do not use "Run previously launched application" in Eclipse. But still the application starts with Splash.JAVA.
What am I doing wrong?
"Check in run configuration which activity is selected." This way android, or in this case eclipse knows which of your activities to start from.
In the future, if you know the answer to one of your questions feel free to answer it yourself. You will be able to accept your own answer in eight hours.
Thanks to shashank Kane for providing the answer
I just created my first Android app, all works fine, but all of the activities are shown on my Android menu. What did I do wrong?
Screenshot: imgur.com/9CmXU
I want to have one icon, directing to MainActivity, not all activities
<!-- language-all: lang-html -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myApps.birthdaymeter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/my_logo"
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=".BirthdayMeter"
android:label="#string/title_activity_birthday_meter" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AboutWindow"
android:label="#string/title_activity_about_window" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShowResult"
android:label="#string/title_activity_show_result" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is my manifest, changing logo didn't help
The <intent-filter> tag is used to describe the type of Intents that each Activity will respond to. The "android.intent.action.MAIN" action says that this Activity is an entrance point for your Application (think the main method that a java program requires). The "android.intent.category.LAUNCHER" category tells the OS to display the Activity in your list of Applications. Adding the DEFAULT category is ok, but effectively the same as omitting the <intent-filter> tag completely (which I find to make for much cleaner and easier to read code). You should only be using the <intent-filter> tag with these two actions and categories on the Activity that starts when a user opens your app. If wanted an Activity within your application to be able to respond to some special intents, you would use the tag to define which it responds to.
Here's a link to the google dev pages to help you learn more about Intent Filters.
http://developer.android.com/guide/components/intents-filters.html
Here's the documentation for the <intent-filter> tag. It's not the easiest to understand though.
http://developer.android.com/guide/topics/manifest/intent-filter-element.html
And here's the docs for the Manifest file and the Intent class. Both of these are good for reference if you're not sure about which tags to use in your Manifest. Good luck!
http://developer.android.com/guide/topics/manifest/manifest-intro.html
http://developer.android.com/reference/android/content/Intent.html
You phrased your question extremely generally, so I am not sure what to answer. It seems like you haven't called nameOfActivity.this.finish() when you launched another activity
If you post your manifest file I can help a little more, but it looks to me like you have not declared your activities correctly.
It should be setup somewhat like this:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="Activity1"></activity>
<activity android:name="Activity2"></activity>
<activity android:name="Activity3"></activity>
</application>
Essentially, create an application declaration, and then include each activity within it.