faraz13 faraz13 - 6 months ago 14
Android Question

multiple activities and intents in android

Hi guys

i have simple android app with 3 activity A,B,C

A activity is the main activity and B,C are the childes.

A | -> B

A | -> C

i already know how to move to other activity by buttons
but i have strange problem
when i start the app,i can only go to those activity for first time and when i press back btn to main activity & press button of another activity the app will crush and show this error "Unfortunately, app has stopped."

For example
when Main activity (a) is loaded i will click the btn of 2ndActivity (B)
and it will open 2nd activity successfuly

But

when i press back system btn and try to click the btn of 3rd activity (c)
the app will failed and show error

note that only each activity that click for first time will be lunch successfuly
I mean if I click btn of C activity for first time then the activity B wont work and show error

note no error found in LogCat and app run correctly in emulators,problem will happen on some phone like my gs4 not all phone

sorry for my bad English

I need your help ,Thanks

My MainActivityA.java

public class MainActivityA extends ActionBarActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
android.support.v7.app.ActionBar AB = getSupportActionBar();
AB.hide();
setContentView(R.layout.activity_mainA);

ImageButton b1 = (ImageButton) findViewById(R.id.imagebtndb1);
b1.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
Intent i = new Intent(MainActivityA.this, MainActivityB.class);
startActivity(i);
}
});


ImageButton b2 = (ImageButton) findViewById(R.id.imagebtndb3);
b2.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
Intent i2 = new Intent(MainActivityA.this, MainActivityC.class);
startActivity(i2);
}
});


My MainActivityB

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
android.support.v7.app.ActionBar AB=getSupportActionBar();
AB.hide();
setContentView(R.layout.activity_main_activity2);
WebView webView = (WebView) findViewById(R.id.webView);
webView.setHorizontalScrollBarEnabled(false);
webView.setVerticalScrollBarEnabled(false);
webView.setBackgroundColor(0);
webView.loadUrl("file:///android_asset/htm.html");



}


my MainActivityC

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
android.support.v7.app.ActionBar AB=getSupportActionBar();
AB.hide();
setContentView(R.layout.activity_main_activity4);
}


my manifest

<?xml version="1.0" encoding="utf-8"?>




<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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>
<activity
android:name=".MainActivityB"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.activityB" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainActivityC"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.activityC" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>



Answer

Have you tried changing your intent filter in your manifest to the full path of the classes

e.g

intent-filter

     action android:name="<full domain name here>.activityB"

intent-filter

     action android:name="com.myandroid.app.activityB"

try it for both activityB and activityC.