Reputation: 157
I know there are plenty of questions about this but I just can't work out why my program keeps loading the wrong activity even though I've made the correct one the default in the manifest. Here's some code for you all:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="swin.examples"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="swin.examples.TemperatureConvertor"
android:label="@string/app_name">
</activity>
<activity android:name="swin.examples.FeetToCmConvertor"
android:label="@string/app_name">
</activity>
<activity android:name="swin.examples.Main" 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>
And here's where I think the problem will be if it's not in the manifest:
package swin.examples;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Main extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initializeUI();
}
private void initializeUI()
{
Button btnCm = (Button)findViewById(R.id.btnFeet);
btnCm.setOnClickListener(btnFeetListener);
Button convertButton = (Button)findViewById(R.id.btnTemp);
convertButton.setOnClickListener(btnTempListener);
}
/** Handle convert button click */
private OnClickListener btnTempListener = new OnClickListener()
{
public void onClick(View v)
{
convertButtonClicked();
}
};
private OnClickListener btnFeetListener = new OnClickListener()
{
public void onClick(View v)
{
btnCmClicked();
}
};
private void btnCmClicked()
{
// set the sender and the receiver of the intent
Intent intent = new Intent();
intent.setClass(getApplicationContext(), swin.examples.FeetToCmConvertor.class);
startActivity(intent); // transmit your intent
}
private void convertButtonClicked()
{
// set the sender and the receiver of the intent
Intent intent = new Intent();
intent.setClass(getApplicationContext(), swin.examples.TemperatureConvertor.class);
startActivity(intent); // transmit your intent
}
}
I can't work it out and I hope you can help me! Thank you so much in advance!
EDIT: Code updated, but still doesn't work. If this helps, this is the log messages:
[2013-04-20 22:44:20 - CombinedConvertor] Success!
[2013-04-20 22:44:21 - CombinedConvertor] Starting activity swin.examples.TemperatureConvertor on device emulator-5554
[2013-04-20 22:44:23 - CombinedConvertor] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=swin.examples/.TemperatureConvertor }
Upvotes: 2
Views: 176
Reputation: 157
Weirdest bug ever. Worked for everyone else, just not me. Remade temperatureconverter activity and it works now. Thank you everyone for your help!
Upvotes: 0
Reputation: 40193
Proper IntentFilter
for the main Activity
is
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Upvotes: 3