Gradle项目同步失败.
更新android SDK后我收到此错误:
错误:无法找到:com.google.android.gms:play-services:5.2.8
android gradle google-play-services android-studio build.gradle
我在BroadcastReceiver中需要一个Activity,但是当我尝试将上下文转换为activity时,它不起作用.
引起:java.lang.ClassCastException:android.app.ReceiverRestrictedContext无法强制转换为android.app.Activity
如何从BroadcastReceiver获取Activity?
谢谢
我正在尝试创建一个Android服装应用程序,其中只有一个活动,其中包含一个片段.我希望能够根据按钮点击或其他用户操作切换片段.
我可以很好地替换碎片; 但是,当我从屏幕左侧滑动到屏幕右侧时.该应用关闭.我希望这个滑动就像一个后退按钮,而不是退出应用程序.
主要活动
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.wearable.view.WatchViewStub;
public class MainActivity extends FragmentActivity implements FragmentChangeListener {
int fragmentContainerId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
final WatchViewStub stub = (WatchViewStub)findViewById(R.id.watch_view_stub);
// instialize the fragment to the loading page
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub watchViewStub) {
fragmentContainerId = R.id.fragmentContainer;
if (watchViewStub.findViewById(R.id.fragmentContainer) != null) {
Fragment1 fragment1= new Fragment1 ();
// In case this activity was started with special instructions from …
Run Code Online (Sandbox Code Playgroud)