How exactly is default activity defined?
As far as I can tell, adding "andriod.intent.action.MAIN" to AndroidManifest.xml like this:
<application
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN/>
That should define .MainActivity as the default activity, but it's not working. I've also tried adding the full package name com.package.MainActivity but that's also not working.
This is probably caused by my layout setup, I'm trying to define a layout dynamically in code... here's my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/mainlao">
</LinearLayout>
Then I define my TextureView layout in onCreate here:
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
LinearLayout layout = (LinearLayout) findViewById(R.id.mainlao);
mButton = new Button(this);
mButton.setText("pic");
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(this);
layout.addView(mTextureView);
layout.addView(mButton, lp);
setContentView(layout);
}
I can't see how my layout would effect it, but this is the first time I've had this error, and the first time I tried doing a layout like this. No errors in code, and I tried invalidating caches.
Google hasn't turned up much yet, except for that android.intent.action.MAIN.. any help is appreciated.
Let me know if you need more information about the app.
The activity's category should be of type 'Launcher'
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN/>
<category android:name="android.intent.category.LAUNCHER" /> // This
</intent-filter>
</activity>
Related
Initially my Android project had only one activity named MainActivity. Then, I added a new activity named ChildActivity into my project. I'm trying to launch my new activity as startup activity when app gets launched. I changed AndroidManifest.xml file to achieve it. I moved the entire intent-filter tag from MainActivity to ChildActivity as shown below:
<activity android:name=".MainActivity">
</activity>
<activity android:name=".ChildActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Layout file of ChildActivity looks like this. I'm trying to show a TextView on the new activity I've just added:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChildActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_display"
android:text="Hello this is Rasik!"/>
</android.support.constraint.FrameLayout>
ChildActivity.java file:
package com.example.android.explicitintent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class ChildActivity extends AppCompatActivity {
private TextView mDisplayText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child);
}
}
Whenever I try to debug my app in Android AVD, nothing happens. It seems my app is crashing at start up. Can anyone help me in diagnosing the root cause?
The class android.support.constraint.FrameLayout not exists. Try LinearLayout, FrameLayout, android.support.constraint.ConstraintLayour or others
please try this !
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_display"
android:text="Hello this is Rasik!"/>
</FrameLayout>
i think there is issue with root framelayout
You used wrong layout.
Just convert android.support.constraint.FrameLayout to FrameLayout.
Or convert to default android.support.constraint.ConstraintLayout
<FrameLayout
...>
<TextView
...
/>
</FrameLayout>
The Root layout android.support.constraint.FrameLayout you are using does not exist. Check out this link Android Developer guide.
Your Root layout can be:
FrameLayout
LinearLayout
RelativeLayout
ConstraintLayout
There are many layouts available which you can use based on your need.
I had seen a similar issue in another post. Just off the bat, it seems like your child activity is not within the enclosing terms of the ".MainActivity."
Put the child activity into the brackets of the ".MainActivity", in between the
<activity android:name=".MainActivity"> </actvitiy>. Hopefully that makes it run better. If that doesn't work, start the child activity during the onCreate() method of the MainActivity.
I'm new to Android Application development. I just added another activity tag in my AndroidManifest.xml file but its gives me the following message : Can't resolve symbol 'SecondActivity' Validates resource references inside Android XML files.
I want to know why is this message getting displayed?
Here is my AndroidManifest.xml file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aupadhyay.myfirstapp">
<application
android:allowBackup="true"
android:icon="#mipmap/amiticon"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="anything" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
And this is my SecondActivity.java file :
import android.support.v7.app.AppCompatActivity;
public class SecondActivity extends AppCompatActivity {
}
Picture :
Consider the following:
Remove the intent-filter inside your second activity unless you really need that.
In your second activity, override onCreate method
#override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity_layout);
}
Did you create a layout for your second activity? It seems your activity is empty - although this might not be the cause of your problem. Also what is the location of your SecondActivity, a different package or in the same place as the first activity?
As shown in your code, your second activity doesn't seem to have any of that layout stuff!
I hope this helps you!
It seems your SecondActivity doesn't belongs to the package "com.aupadhyay.myfirstapp", So move it to src of the "com.aupadhyay.myfirstapp" package where ever it currently belongs to.
I'm an Android noob and I'm having difficulty finding out something basic about Android.
I currently have an activity_main.xml file.
I want to use this layout when I first start the Android emulator, using Android Studio
Does Android look for a file activity_main.xml and use it as the default layout?
Here's my AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
So I understand that this specifies that my .MainActivity will respond to an action.MAIN intent call. What I don't know is what the action.MAIN intent call actually is, and how my activity_main.xml relates to this.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Can anyone provide an explanation or a link to a good primer that explains these basic concepts?
From manifest :
<action android:name="android.intent.action.MAIN" />
Means this activity is the entry point of the application. In your case, the MainActivity starts.
The MainActivity sets up the layout for itself - the line responsible is
setContentView(R.layout.activity_main);
Where it looks for layout file activity_main.xml. This is just the naming convention - feel free to rename the layout file and call the new one from setContentView. It's not required to be called activity_main
yesterday i created a Desk clock for android. For this I created a RelativeLayout to show Hours,minutes,etc... and a menu to show the options About, and Exit...Well, all works fine, but the problem comes when I click About Option: it force Closes and LogCat shows this:
E/AndroidRuntime(14751): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.iamaner.T2Speech/com.iamaner.T2Speech.FrmAbout}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
So I hope you can help me...
Ive heard about this code, but i dont know where to put it,and how, i thought this would be Ok but it seems not
final RelativeLayout fondo = (RelativeLayout)findViewById(R.id.your_layout);((RelativeLayout)fondo.getParent()).removeView(fondo);
//scrollView.removeView(scrollChildLayout);
Here is the manifest file i think its the problem, i dont know:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TimeToSpeechActivity"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FrmAbout" />
</application>
And here, the FrmAbout code:
public class FrmAbout extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frmabout);
TextView txtVersion = (TextView)findViewById(R.id.Txtversion);
TextView txtWarning = (TextView)findViewById(R.id.Txtwarning);
TextView txtInstructions = (TextView)findViewById(R.id.Txtinstructions);
TextView txtContact = (TextView)findViewById(R.id.Txtcontact);
setContentView(txtVersion);
setContentView(txtWarning);
setContentView(txtInstructions);
setContentView(txtContact);
}
}
Ok, solved it.... the problem was the setcontentview() method, deleted it and now it works
From your code i didn't understood Why you removing all views before calling About activity? Is this any of your requirement because to start new activity all the views need not be removed.. You can directly call startActivity(intent) without removing views from current activity.
Please post logs to help understand the problem.
I'm new to Android programming and i'm doing tutorial from layouts from http://developer.android.com/resources/tutorials/views/index.html . Relative layout tutorial exactly. I did everything they say but when I try to start app in android emulator there are no buttons, textfields etc. Only name of app shows at the top. What is wrong? Is this a problem with emulator? I'm using Eclipse Version: 3.7.1.
EDIT:
package pchot.tutorial;
import android.app.Activity;
import android.os.Bundle;
public class Tutorial1Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pchot.tutorial"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Tutorial1Activity"
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>
Layout is copy/paste from http://developer.android.com/resources/tutorials/views/hello-relativelayout.html
EDIT:
Ok, problem solved. I needed to delete "Hello World, Tutorial1Activity!" from string.xml file which was autocreated during creation of project in Eclipse.
Have you modified you manifest.xml file? Maybe you haven't modify it to make it aware that the launched main activity is the activity you've just created.
You didn't declare anything in your onCreate() method.
For Button declare Button btn = (Button)findViewById(R.id.btnSubmit)
Implement onClickListener if you want the button to listen to clicks.
For TextView, declare TextView tv = (TextView)findViewById(R.id.textview)