/**
 * Copyright 2014-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the
 * LICENSE-examples file in the root directory of this source tree.
 */

package com.facebook.samples.litho;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.facebook.litho.ComponentContext;
import com.facebook.litho.LithoView;

public class DemoActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final String demoName = (String) getIntent().getSerializableExtra("demoName");

    setContentView(
        LithoView.create(
            this,
            Demos.getComponent(demoName)));
  }
}

/**
 * Copyright 2014-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the
 * LICENSE-examples file in the root directory of this source tree.
 */

package com.facebook.samples.litho;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.facebook.litho.ComponentContext;
import com.facebook.litho.LithoView;

public class DemoActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Demos.initialize(this);

    final String demoName = (String) getIntent().getSerializableExtra("demoName");

    setContentView(
        LithoView.create(
            this,
            Demos.getComponent(demoName)));
  }
}

Fix weird base context bug in sample app
Fix weird base context bug in sample app

Summary:
The demo components are created when you start DemoListActivity and stored in a static map.  Each individual demo however, runs in DemoActivity. This means you can get a component with a context based on activity (DemoListActivity) that gets mounted in a view created by a context based on another activity (DemoActivity) and fail ComponentTree#hasSameBaseContext().

This diff makes the easy fix by re-initializing the demos in each activity. That way we insure the components and views they're mounted in have the same base activity.

Reviewed By: emilsjolander

Differential Revision: D4881062

fbshipit-source-id: 5051647854f3bce564b304b0d92cff656eba56b1
