Skip to content Skip to sidebar Skip to footer

Startactivity() Not Working From Inner Class That Extends Listactivity

Title basically says it all. The below code doesn't throw any errors, it just doesn't start the new activity. Code below. I have tried modifying startActivity(new Intent(mCtx, Ne

Solution 1:

Possible cause 1

The activity has not been declared.

You have to add the activity to your AndroidManifest.xml

You should add this to your <application> tag in your AndroidManifest.xml:

<activityandroid:name="package.name.NewActivity"><!-- Add an intent filter here if you wish --></activity>

Possible cause 2

The onChange method doesn't actually run.

Please use the code below to verify that the onChange method actually gets called:

publicclassMyListActivityextendsListActivity {
    MyContentObserver mContentObserver;

    @OverridepublicvoidonCreate(Bundle onSavedInstance) {
        super.onCreate(onSavedInstance);
        setContentView(R.layout.calls_list);

        mContentObserver = newMyContentObserver();

        this.getApplicationContext().getContentResolver().registerContentObserver(CallLog.Calls.CONTENT_URI, true, mContentObserver);
    }

    privateclassMyContentObserverextendsContentObserver {
        publicMyContentObserver() {
            super(null);
        }

        @OverridepublicvoidonChange(boolean selfChange) {
            super.onChange(selfChange);
            Log.d("MyListActivity.MyContentObserver", "onChange");
            startActivity(newIntent(MyListActivity.this, NewActivity.class));
        }
    }   
}

You could also try launching the activity from onCreate to make sure it can be launched.

Post a Comment for "Startactivity() Not Working From Inner Class That Extends Listactivity"