小编Nik*_*ski的帖子

如何查找活动是否是堆栈中的最后一个活动

我在我的应用程序中打开一个链接,一旦按下后我想显示HomePage以保留用户更多时间.我一直在努力实现这一目标但却无法做到这一点.我将homeLauncher活动作为我的top和baseActivity.

DeepLink Tap>打开所需的活动>用户按下后退按钮>检查其上一个活动但不是homeActivity>如果是,请将用户导航到homeActivity.

尝试以下代码:

@Override
public void onBackPressed() {
ActivityManager mngr = (ActivityManager) getSystemService( ACTIVITY_SERVICE );
List<ActivityManager.RunningTaskInfo> taskList = mngr.getRunningTasks(10);

if(taskList.get(0).numActivities == 1 && taskList.get(0).topActivity.getClassName().equals(this.getClass().getName())){
  //// This is last activity
}
else{
    //// There are more activities in stack
}

super.onBackPressed();
}
Run Code Online (Sandbox Code Playgroud)

Android Studio Evalation

我也试过isTaskRoot但结果是一样的.它没有给出正确的答案.请帮助

android android-intent android-activity back-stack activity-manager

13
推荐指数
2
解决办法
4540
查看次数

如何在Retrofit中检索cookie?

我读到了请求拦截器以及什么不是但不知道如何真正使用它们来获取cookie ...我从nodejs发送这样的cookie ...

res.cookie('userid', user._id, { maxAge: 86400000, signed: true, path: '/' });
Run Code Online (Sandbox Code Playgroud)

在我的Android客户端 - 我为RestApiManager设置了这个

public class RestApiManager {
  private static final String API_URL = "ip: port";

    private static final RestAdapter REST_ADAPTER = new RestAdapter.Builder()
            .setEndpoint(API_URL)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .build();

    //Call interface
    public interface AsynchronousApi {
  //Login User
        @FormUrlEncoded
        @POST("/login")
        public void loginUser(
                @Field("loginName") String loginName,
                @Field("password") String password,
                Callback<UserResponse> callback);
//Profile Picture
        @Multipart
        @POST("/profilePicture")
        public void uploadProfilePicture(
                @Part("photo") TypedFile photo,
                @Part("userId") String userId,
                Callback<UserResponse> callback); //success thumbnail to picasso

    } …
Run Code Online (Sandbox Code Playgroud)

cookies android retrofit

12
推荐指数
1
解决办法
1万
查看次数

清除Picasso的缓存

我试图通过Android编码清除Picasso的缓存.

任何人都可以帮我解决这个问题..?

我尝试使用以下代码,但这在我的情况下没用:

Picasso.with(getActivity()).load(data.get(pos).getFeed_thumb_image()).skipMemoryCache().into(image);
Run Code Online (Sandbox Code Playgroud)

memory android caching picasso

12
推荐指数
4
解决办法
4万
查看次数

直播RTSP流不能与VideoView一起播放; 没有内容提供商错误

我是Android开发的新手,似乎无法通过开发应用程序来从ip摄像头直播RTSP源.虽然我可以从具有.mov文件的RTSP地址的网站流式传输代码,但我无法从我的ip camera的RTSP地址流式传输.我们正在使用,VideoView以便我们可以支持回到Android 4.0,因为我们的目标是在Epson Moverio BT-200视频眼镜中显示它.

下面是我现在的代码,我可以从相机中注释掉两条流的线条.未注释掉的行是在线测试流,可以正常播放.

VideoView videoView;
@Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    //Create a VideoView widget in the layout file
    //use setContentView method to set content of the activity to the layout file which contains videoView
    this.setContentView(R.layout.activity_full_screen_video);
    videoView = (VideoView)this.findViewById(R.id.video_player_view);

    //Set the path of Video or URI
    //videoView.setVideoPath("rtsp://192.168.1.122/h264");
    //videoView.setVideoPath("http://192.168.1.122/ipcam/mjpeg.cgi");
    videoView.setVideoPath("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");

    //Set the focus
    videoView.requestFocus();
    videoView.start();
}
Run Code Online (Sandbox Code Playgroud)

当使用从ip camera中提取的任一行运行时,我们会收到以下错误:

'setDataSource IOException happend :
java.io.FileNotFoundException: No content provider: http://192.168.1.122/ipcam/mjpeg.cgi'
Run Code Online (Sandbox Code Playgroud)

来自相机的RTSP流已经使用另一个rtsp android应用程序进行了验证,所以我知道它并不坏.

是否必须采取措施才能进行缓冲?最终目标是尽可能接近实时直播到应用程序,在眼镜中进行视频叠加.但是,我们甚至无法获得显示的基本流.欢迎任何和所有建议!

android rtsp live-streaming http-live-streaming android-mediaplayer

11
推荐指数
1
解决办法
2678
查看次数

使用Android 5.0设备在CardView上将selectableItemBackground显示为前景的涟漪

我在Nexus 5上运行它.这是我的CardView代码的一部分:

        CardView cardView = new CardView(getActivity());
        cardView.setRadius(4);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 400);
        lp.setMargins(32, 16, 32, 16);
        cardView.setLayoutParams(lp);
        cardView.setContentPadding(50, 50, 50, 50);
        ...
        cardView.setForeground(selectedItemDrawable);
Run Code Online (Sandbox Code Playgroud)

这是我如何获得selectedItemDrawable:

        int[] attrs = new int[] { R.attr.selectableItemBackground };
        TypedArray ta = getActivity().obtainStyledAttributes(attrs);
        selectedItemDrawable = ta.getDrawable(0);
        ta.recycle();
Run Code Online (Sandbox Code Playgroud)

当我点击卡片时,不会出现与selectedItemDrawable一起出现的波纹(它看起来与没有前景设置完全相同).我正在运行5.0,所以这看起来很奇怪,因为appcompat文档只说它不适用于pre-Lollipop设备.有人知道为什么会这样吗?最低API级别为16,目标为21.

android android-cardview rippledrawable android-5.0-lollipop

10
推荐指数
1
解决办法
7836
查看次数

在屏幕旋转期间保存BottomNavigationView所选项目

使用ASL的25.0 BottomNavigationView我遇到了一些麻烦,比如保存所选项目(或他的索引)和编程选择的项目.

android android-support-library android-support-design

10
推荐指数
2
解决办法
3991
查看次数

onItemSelectedListener仅在选择实际更改时触发?

setOnItemSelectedListener在旋转器上使用.如果我更改了选择,则会触发侦听器,但如果我选择了已选择的相同项目则不会触发.即使用户选择了已经选择的相同项目,我也需要被nofified.我一直在努力使用,setOnItemClickListener但它不受支持Spinner.

任何提示?

TIA

android spinner

9
推荐指数
1
解决办法
2500
查看次数

Android onStop/onDestroy - 什么时候可以使用?

看一下活动生命周期图,我注意到onPause()并且onStop()都可能导致"进程"被杀死.onCreate()当用户想要恢复其应用程序时,需要调用它.重点onStop()不一定是,也不是onDestroy(),但这onPause()可能是活动可能看到的唯一事件.在这种情况下,onPause()必须处理保存应用程序状态,以便用户以后可以返回它,无论是否onStop()被调用.

我可以看到onDestroy()用于清理活动特定资源,这些资源在进程终止操作中自然会被消除.还有什么比这onDestroy()更好的吗?

那会有什么onStop()好处?我为什么要覆盖它?

android

9
推荐指数
1
解决办法
1万
查看次数

如何在折叠时更改工具栏图标颜色

我在我的项目中使用CoordinatorLayout.它工作正常,但我需要修复一个问题.我正在使用白色操作栏图标,当CoordinatorLayout展开并且背景颜色为白色时,我看不到任何这些图标.

我在一个应用程序中看到了这个 当CoordinatorLayout展开时,图标会变暗,当向下滚动时,它们会变为白色.

http://i.stack.imgur.com/rCCQb.png

正如您所看到的,当它被展开时,图标是黑暗的,当它关闭时,图标变为白色.

向下滚动直到它完全从黑暗图标转换为白色图标开始变化

抱歉没有附上代码,这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="240dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="#FF4548"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:id="@+id/slidelayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="?attr/actionBarSize"
            android:background="#fff">

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

            <com.viewpagerindicator.CirclePageIndicator
                android:id="@+id/indicator"
                android:layout_width="fill_parent"
                android:layout_height="10dp"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="7dp" />
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:paddingLeft="3dp"
            android:layout_gravity="top"
            android:paddingRight="3dp"
            app:layout_collapseMode="pin">

            <ImageView
                android:id="@+id/imgsearch"
                android:layout_width="wrap_content"
                android:layout_height="?attr/actionBarSize"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="2dp"
                android:paddingBottom="5dp"
                android:src="@drawable/ic_action_search"
                android:visibility="visible" />

            <ImageView
                android:id="@+id/imgshare"
                android:layout_width="wrap_content"
                android:layout_height="?attr/actionBarSize"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="5dp"
                android:layout_toRightOf="@+id/imgsearch"
                android:paddingBottom="5dp"
                android:src="@drawable/ic_action_share"
                android:visibility="visible" />

            <ImageView …
Run Code Online (Sandbox Code Playgroud)

android android-toolbar android-collapsingtoolbarlayout

9
推荐指数
1
解决办法
3756
查看次数

使用SeekBarPreference

与SeekBarPreference有什么关系?让我扩大......

如果我在我的PreferenceScreen xml中放置一个SeekBarPreference,它可以正常工作(我可以在手机和模拟器上运行它),但是Android Studio报告在这里不允许使用Element SeekBarPreference.简单的XML显示了这一点:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<SeekBarPreference
    android:key="fontSize"
    android:title="@string/fontSize_title"
    android:summary="@string/fontSize_summary"
    android:max="12"
    android:defaultValue="4" />

</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

如果我尝试扩展SeekBarPreference(这是我真正想做的事情),Android Studio Cannot resolve symbol SeekBarPreference既可以使用import也可以使用extends.简单的Java文件来显示这个:

import android.preference.SeekBarPreference;

public class FontSizePreference extends SeekBarPreference {}
Run Code Online (Sandbox Code Playgroud)

(如果我只是SeekBarPreference sbp;在代码中使用也会发生.)

SeekBarPreference的源代码/Sdk/sources/android-22/android/preference就像EditTextPreference一样.我没有看到任何特别之处.

但是,我在developer.android.com上找不到任何关于它的文档.

我错过了哪些信息?与EditTextPreference相比,有什么特别之处,我可以将其包含在XML中并在代码中扩展和使用而不会出现问题?

android seekbarpreference

8
推荐指数
1
解决办法
1518
查看次数