成功启动以下意图后:
startActivity(new Intent(Intent.ACTION_VIEW, SOME_URL));
浏览器启动正常并加载链接,但当我尝试返回我的应用程序时,响应缓慢。当应用程序最终启动时,我遇到了黑屏,最后是“应用程序无响应”对话框。
logcat没有错误,没有明显的内存问题,没有任何迹象表明我做错了什么。
启动intent的活动是一个非常简单的活动,有一个片段:
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);
}
}
}
该片段使用RxJava,RetroFit和Dagger‡的组合来加载链接列表:
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());
}
}
答案 0 :(得分:0)
在找到两个类似答案的相似问题(How to spot app freeze causes when app is returning from pause state?,Android App freezes after implementing Google Firebase)之后,建议添加Google Play服务可能是罪魁祸首,我开始调查。
两个答案都建议我删除以下依赖项:
compile 'com.android.gms:play-services:9.0.2'
但我的应用程序使用该依赖项,以及以下播放服务依赖项:
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'
以前,我一直在我的移动模块和磨损模块中使用核心播放服务库和可穿戴游戏服务库中的类。但我注意到我已经移除了移动模块中磨损模块的需要,因此我将其从移动模块中移除(同时将其保留在磨损模块中)。不知何故,这解决了这个问题。
我不知道为什么,所以如果有人有任何想法,请分享。