I've just began on a new application and I added a button which in the past I've had no problem with but for some reason Its not working now. I'm just simply trying to teacher that button to another page. What do you think the problem is? (just ignore the spinners I haven't set those up yet)
TextingprojectActivity
public class TextingprojectActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button tut1 = (Button) findViewById(R.id.tutorial1);
tut1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("practice.practice.TUTORIALONE "));
}
});
}
}
Tutorial1 Java
public class TutorialOne extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
}
}
Main XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/place_arrays"
android:prompt="#string/Place"/>
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/tutorial1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/save"
/>
</LinearLayout>
tutorial1 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" >
</LinearLayout>
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="practice.practice"
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=".TextingprojectActivity"
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=".TutorialOne"
android:label="#string/app_name">
<intent-filter>
<action android:name="practice.practice.TUTORIALONE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
change your intent call like
Intent n = new Intent(TextingprojectActivity.this,TutorialOne.class);
startActivity(n);
Also remove the intent-filter from the delaration of the rest activity from maniefst.
<intent-filter>
<action android:name="practice.practice.TUTORIALONE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Change it to like...
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".TextingprojectActivity"
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=".TutorialOne"
android:label="#string/app_name">
</activity>
</application>
Change your intent call to
Button tut1 = (Button) findViewById(R.id.tutorial1);
tut1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent n = new Intent(TextingprojectActivity.this,TutorialOne.class);
startActivity(n);
}
});
if simply need to redirect to second activity Change your code as
Button tut1 = (Button) findViewById(R.id.tutorial1);
tut1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(TextingprojectActivity.this,TutorialOne.class););
}
});
And Remove this Block From your manifest XML
<intent-filter>
<action android:name="practice.practice.TUTORIALONE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
What is this practice.practice.TUTORIALONE???
Related
So when this code runs I get no errors. It displays the buttons correctly and everything, but when I click on the button nothing happens (it just clicks and clicks and clicks nothing happens).
Below I will post the xml manifest so you can see that I have done everything perfectly, but somehow it it is not doing what I am asking it to do.
package com.Tripp.thebasics;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Menu extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.jokecatagories);
//setting up the button references
Button jokeD = (Button) findViewById(R.id.jokeoftheday);
Button jokeC = (Button) findViewById(R.id.jokecatagories);
jokeD.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(),JokeOfTheDay.class);
startActivity(i);
}
});
jokeC.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent s = new Intent(".JokeCatagories");
startActivity(s);
}
});
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Tripp.thebasics"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Main"
android:label="#string/app_name"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".com.Tripp.thebasics.JokeCatagories"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.JOKECATAGORIES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Sweet"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SWEET" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".com.Tripp.thebasics.JokeOfTheDay"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.JOKEOFTHEDAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Change your OnClickListeners as follows...
jokeD.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Menu.this, JokeOfTheDay.class);
startActivity(i);
}
});
jokeC.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent s = new Intent(Menu.this, JokeCatagories.class);
startActivity(s);
}
});
Then get rid of this <intent-filter> from the JokeCategories <activity> section in the manifest...
<intent-filter>
<action android:name="android.intent.action.JOKECATAGORIES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
...and get rid of this one from the JokeOfTheDay <activity> section...
<intent-filter>
<action android:name="android.intent.action.JOKEOFTHEDAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Basically, don't use the application Context to start an Activity (it's not necessary from an Activity as it has its own Context) and, on the whole, use explicit Intents to start Activities rather than defining <intent-filter> section in the manifest.
I am trying go from one activity to its sub-activity (i.e, a new page with more buttons), but every time I click the button, the application "Unfortunately stops running".
I believe that the flaw lies in the manifest where I might writing something wrong under the intent-filter section.
Mind taking a look?
public class MainActivity extends ActionBarActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
addListenerOnButton2();
}
//First Activity
private void addListenerOnButton() {
// TODO Auto-generated method stub
button = (Button) findViewById(R.id.activity_one);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent IntentOne =
new Intent(arg0.getContext(), ActivityOne.class);
arg0.getContext().startActivity(IntentOne);
}
});
}
//Second Activity, will look into it later. Making it Explicit for now.
public void addListenerOnButton2() {
button = (Button)findViewById(R.id.activity_two);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View argo) {
Intent IntentTwo = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.ca"));
startActivity(IntentTwo);
}
});
}
}
///////////////////////////////////////////////////////
Here is the Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.poop"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.poop.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.poop.ActivityOne"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.poop.ActivityOne" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I have not added ActivityTwo yet to the manifest.
You can't have Activities that aren't registered in the Manifest. I don't see an ActivityOne registered in your AndroidManifest.xml
I am working in Eclipse on an android app which starts with a splash screen (suspecting Memory Leak here after some research done). The splash screen goes into the main menu consisting of just 7 buttons which lead to some Java Applet. The whole app was working perfectly until I changed the 7 dummy (ImageButton) png images to the finalized 7 png images. These png images have an average of 10KB and don't think they are the cause of the problem (since they're this small), even though this problem started after I changed these png images of the ImageButtons.
Honestly I don't know where to start apart from resizing the images again, cause they are designed a bit large as size in pixels (not memory) to fit different devices. But I think there is another solution to this problem which I as a beginner cannot figure out. I hope someone can help me with this problem :)
Here is the code:
Manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.letsfly.tryp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:debuggable="true" >
<activity
android:name=".Splash"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="com.letsfly.tryp.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Testing"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="com.letsfly.tryp.TESTING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".trypOne"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.letsfly.tryp.TRYPONE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".trypTwo"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.letsfly.tryp.TRYPTWO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".trypThree"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.letsfly.tryp.TRYPTHREE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".trypFour"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.letsfly.tryp.TRYPFOUR" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".trypFive"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.letsfly.tryp.TRYPFIVE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Splash XML.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="600dp"
android:layout_height="800dp"
android:layout_gravity="center"
android:layout_marginTop="-180px"
android:contentDescription="#string/button1"
android:padding="0px"
android:src="#drawable/trypsplash" />
</LinearLayout>
Splash Java.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle waitFiveSeconds) {
// TODO Auto-generated method stub
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(waitFiveSeconds);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openMenu = new
Intent("com.letsfly.tryp.MAINACTIVITY");
startActivity(openMenu);
}
}
};
timer.start();
}
}
MainActivity Java (where the buttons are).
package com.letsfly.tryp;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
public class MainActivity extends Activity {
ImageButton button1;
ImageButton button2;
ImageButton button3;
ImageButton button4;
ImageButton button5;
ImageButton button6;
ImageButton button7;
#Override
protected void onCreate(Bundle savedInstanceState) {
//replace yourActivity.this with your own activity or if you declared a context you can write context.getSystemService(Context.VIBRATOR_SERVICE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (ImageButton) findViewById(R.id.imageButton1);
button2 = (ImageButton) findViewById(R.id.imageButton2);
button3 = (ImageButton) findViewById(R.id.imageButton3);
button4 = (ImageButton) findViewById(R.id.imageButton4);
button5 = (ImageButton) findViewById(R.id.imageButton5);
button6 = (ImageButton) findViewById(R.id.imageButton6);
button7 = (ImageButton) findViewById(R.id.imageButton7);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent goToTrypOne = new Intent("com.letsfly.tryp.TRYPONE");
startActivity(goToTrypOne);
}
});
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent goToTrypTwo = new Intent("com.letsfly.tryp.TRYPTWO");
startActivity(goToTrypTwo);
}
});
button3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent goToTrypThree = new Intent("com.letsfly.tryp.TRYPTHREE");
startActivity(goToTrypThree);
}
});
button4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent goToTrypTwo = new Intent("com.letsfly.tryp.TRYPFOUR");
startActivity(goToTrypTwo);
}
});
button5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent goToTrypFive = new Intent("com.letsfly.tryp.TRYPFIVE");
startActivity(goToTrypFive);
}
});
button6.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
button7.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
MainActivity XML.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/button1"
android:src="#drawable/button1"
android:layout_weight="1"
android:layout_gravity="center"/>
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/button2"
android:src="#drawable/button2"
android:layout_weight="1"
android:layout_gravity="center" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/button3"
android:src="#drawable/button3"
android:layout_weight="1"
android:layout_gravity="center" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/button4"
android:src="#drawable/button4"
android:layout_weight="1"
android:layout_gravity="center" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/button5"
android:contentDescription="#string/button5"
android:layout_weight="1"
android:layout_gravity="center" />
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/button6"
android:src="#drawable/button6"
android:layout_weight="1"
android:layout_gravity="center" />
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/button7"
android:src="#drawable/button7"
android:layout_weight="1"
android:layout_gravity="center" />
</LinearLayout>
Being large in pixels actually is the issue, as Android will need to inflate the compressed pngs into uncompressed bitmaps in memory to display them.
Instead of making large pngs that scale down to accomodate different size/density devices, instead use drawable folders with different qualifiers:
Images for mdpi devices: /res/drawable-mdpi
Images for hdpi devices: /res/drawable-hdpi
Images for xhdpi devices: /res/drawable-xhdpi
Images for xxhdpi devices: /res/drawable-xxhdpi
When you request an image (say, R.drawable.myImage), it will look for a myImage file in the folder that has the density qualifier that best matches the device. This lets you automatically make sure that small density devices are using images with a smaller memory footprint.
More information here:
http://developer.android.com/guide/practices/screens_support.html
Hello everybody i have a problem that when i click a button it remains as it is instead of starting new activity. I searched he problem in this site and found some solutions but none of them worked for me so i am writing my problem here.
the xml layout is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/profile_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/profile" />
<Button
android:id="#+id/create_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="#string/create_profile" />
<Button
android:id="#+id/edit_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/create_profile"
android:text="#string/edit_profile" />
<Button
android:id="#+id/delete_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/edit_profile"
android:text="#string/delete_profile" />
<Button
android:id="#+id/activate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/delete_profile"
android:text="#string/activate" />
<ListView
android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/create_profile"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#id/profile_title" />
<TextView
android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/create_profile"
android:layout_below="#id/profile_title"
android:gravity="center_vertical|center_horizontal"
android:text="#string/no_profiles" />
</RelativeLayout>
and the activity is
package com.android.SmartSwitch;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Profile_Manager extends Activity {
private Button createButton;
private Button editButton;
private Button deleteButton;
private Button activateButton;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
setUpViews();
}
private void setUpViews() {
createButton = (Button)findViewById(R.id.create_profile);
editButton = (Button)findViewById(R.id.edit_profile);
deleteButton = (Button)findViewById(R.id.delete_profile);
activateButton = (Button)findViewById(R.id.activate);
createButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(Profile_Manager.this, Add_Profile.class);
startActivity(intent);
}
});
editButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
deleteButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
activateButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
}
}
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.SmartSwitch"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".SmartSwitchActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Location_Manager" android:label="#string/app_name"/>
<activity android:name=".Profile_Manager" android:label="#string/app_name"/>
<activity android:name=".Schedule_Manager" android:label="#string/app_name"/>
<activity android:name=".Location_In_Map" android:label="#string/app_name"/>
<activity android:name=".Add_Profile" android:label="#string/app_name"/>
<uses-library android:name="com.google.android.maps" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
When i click createButton, it doesn't respond
As your Main Activity i.e., Profile_Manager consists of the following Code:
<activity
android:label="#string/app_name"
android:name=".SmartSwitchActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You have to note if the Profile Manager class is the class which will be launched i.e., if Profile_Manager Class is the First Screen then, you should create the above code in AndroidManifest.xml with the only change as android:name=".Profile_Manager" instead of "SmartSwitchActivity" with the code additionally added for Add_Profile class as follows
<activity
android:label="#string/app_name"
android:name=".Add_Profile" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I suppose by doing this changes,things will work fine.
If you are not able to understand the above working then,Here is the Link with Perfect Working Example and with available Source Code-Correct Working of Button Click
Ever since I included AdMob into my app everytime I run it and click on a button that goes to a page with Ads on it all I get its "thread exiting with uncaught exception (group=0x40a3b1f8)"
Main java:
package com.co500.gdsg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class GameDevStoryGuideActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button co = (Button) findViewById(R.id.combinations);
co.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.COMBINATIONS"));
}
});
Button jb = (Button) findViewById(R.id.jobs);
jb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.JOBS"));
}
});
Button ty = (Button) findViewById(R.id.type);
ty.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.TYPE"));
}
});
Button con = (Button) findViewById(R.id.consoles);
con.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.CONSOLES"));
}
});
Button gen = (Button) findViewById(R.id.genre);
gen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.GENRE"));
}
});
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
package="com.co500.gdsg"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|uiMode|screenSize|smallestScreenSize"
></activity>
<activity
android:name=".GameDevStoryGuideActivity"
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=".Genre"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.GENRE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Combinations"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.COMBINATIONS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Consoles"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.CONSOLES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Notgood"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.NOTGOOD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Hmm"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.HMM" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Notbad"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.NOTBAD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Creative"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.CREATIVE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Amazing"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.AMAZING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Jobs"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.JOBS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Type"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.TYPE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/genre"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Game Genre Unlocks" />
<Button
android:id="#+id/consoles"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Consoles" />
<Button
android:id="#+id/combinations"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Combinations" />
<Button
android:id="#+id/type"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Game Type Unlocks" />
<Button
android:id="#+id/jobs"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Jobs" />
</LinearLayout>
consoles.xml (similar to the other xmls)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/consoleavail" />
</LinearLayout>
</ScrollView>
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="empty for a reason"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
logcat:
07-13 15:16:13.770: D/dalvikvm(4567): GC_FOR_ALLOC freed 17K, 2% free 7848K/8007K, paused 14ms
07-13 15:16:13.780: I/dalvikvm-heap(4567): Grow heap (frag case) to 9.377MB for 1769056-byte allocation
07-13 15:16:13.810: D/dalvikvm(4567): GC_CONCURRENT freed 2K, 2% free 9573K/9735K, paused 2ms+2ms
07-13 15:16:13.830: D/AndroidRuntime(4567): Shutting down VM
07-13 15:16:13.830: W/dalvikvm(4567): threadid=1: thread exiting with uncaught exception (group=0x40a3b1f8)
07-13 15:16:13.830: E/AndroidRuntime(4567): FATAL EXCEPTION: main
07-13 15:16:13.830: E/AndroidRuntime(4567): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.co500.gdsg/com.co500.gdsg.Consoles}: android.view.InflateException: Binary XML file line #23: Error inflating class com.google.ads.AdView
07-13 15:16:13.830: E/AndroidRuntime(4567): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-13 15:16:13.830: E/AndroidRuntime(4567): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
you are using this below statement
startActivity(new Intent("com.co500.gdsg.CONSOLES"));
Which is causing problem.
use
startActivity(new Intent(ActivityName.this,CONSOLES.class);
first param of Intent should be a context and second should be the className.this is a target class
P.S :- it will show error as ActivityName not found, Please replace ActivityName with your Activity Name.