0

After I successfully launching the following intent:

startActivity(new Intent(Intent.ACTION_VIEW, SOME_URL));

The browser boots up fine and loads the link, but when I try to return to my app the response is sluggish. When the app eventually launches I am met with a black screen, and finally an "Application Not Responding" dialog.

No errors in logcat, no obvious memory issues, nothing to indicate what I did wrong.

The activity that launches the intent is a pretty simple activity, with one fragment:

public class LinkActivity extends AppCompatActivity {

    @BindView(R.id.toolbar) Toolbar mToolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_link);
        ButterKnife.bind(this);

        setSupportActionbar(mToolbar);
        setupActionBar();

        if(savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.content, LinkFragment.newInstance()).commit();
        }
    }

    private void setupActionBar() {
        ActionBar actionBar = getSupportActionBar();

        if(actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(true);
        }
    }

}

And the fragment uses a combination of RxJava, RetroFit and Dagger ‡ to load a list of links:

public class LinkFragment extends Fragment {

    @Inject RestService mRestService;

    @BindView(R.id.recycler) RecyclerView mRecyclerView;

    public static LinkFragment newInstance() {
        return new LinkFragment();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_link, container, false);
        Injector.getContextComponent().inject(this);
        ButterKnife.bind(this, view);

        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext());
        mRecyclerView.addItemDecoration(new DividerDecoration(getContext());
        mRecyclerView.setAdapter(new LinkAdapter(new ArrayList<>()));

        mRestService.getLinks()
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(this::onNext, this::onError);

        return view;
    }

    private void onNext(Response<Link> response) [
        LinkAdapter adapter = new LinkAdapter(response.data());
        adapter.setOnItemClickListener(this::onItemSelected);
        mRecyclerView.swapAdapter(adapter, false);
    }

    private void onError(Throwable throwable) {
        Timber.w(throwable, "Failed to obtain links");
    }

    private void onItemSelected(int position, View view, Link link) {
        startActivity(new Intent(Intent.ACTION_VIEW, link.getUri());
    }

}
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Bryan
  • 14,756
  • 10
  • 70
  • 125

1 Answers1

0

After finding two similar questions with similar answers (How to spot app freeze causes when app is returning from pause state?, Android App freezes after implementing Google Firebase) suggesting that adding Google Play Services might be the culprit, I started to investigate.

Both answers suggested that I remove the following dependency:

compile 'com.android.gms:play-services:9.0.2'

But my application uses that dependency, as well as the following play services dependencies:

compile 'com.google.android.gms:play-services-wearable:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile 'com.google.android.gms:play-services-location:9.0.2'
compile 'com.google.android.gms:play-services-analytics:9.0.2'

Previously, I had been using classes from both the core play services library and the wearable play services library in both my mobile module and my wear module. But I noticed that I had removed the need for the wear module in my mobile module, so I removed it from the mobile module (while keeping it in the wear module). Somehow, this fixed the issue.

I have no clue why, so if anyone has any thoughts, please share.

Community
  • 1
  • 1
Bryan
  • 14,756
  • 10
  • 70
  • 125