I have three intents to switch layouts etc.
Only the first seems to work and the other two are from what I can see, identical. I don't know if I have been staring at this for too long now and I am missing something stupid. Any suggestions?
Before anyone says, I've changed the actual package name etc to com.mysite.myapp. The originals are all spelt as I need them to be.
From my MainActivity
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button general1 = (Button)findViewById(R.id.btngeneral);
general1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent("com.mysite.myapp.general");
startActivity(i);
}
});
Button health1 = (Button)findViewById(R.id.btnhealth);
health1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent("com.mysite.myapp.health");
startActivity(i);
}
});
Button navi1 = (Button)findViewById(R.id.btnnavi);
navi1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent("com.mysite.myapp.navi");
startActivity(i);
}
});
The first one there works totally fine as expected it should.
This is from my manifest:
<activity
android:name="com.mysite.myapp.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=".general"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.mysite.myapp.general" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".health"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.mysite.myapp.health" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".navi"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.mysite.myapp.navi" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
The class of the working intent
public class general extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.general);
}
}
The classes of the two non working intents
public class health extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.health);
}
}
and
public class navi extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navi);
}
}
I hope someone has some good suggestions as I've been staring at this now for far too long.
First check your Application package (the package name that you declared in manifest) and all Activities package names are same... if yes, your code should work. if no, declare your Activities in manifest with fully qualified package name
if not yet, try this (give least preference to below way)
replace
Intent i = new Intent("com.mysite.myapp.general");
startActivity(i);
with
Intent i = new Intent(MainActivity.this,general.class);
startActivity(i);
and do change for other things also
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments