在进行API调用时,我很少收到此错误.
java.lang.IllegalStateException: Fragment not attached to Activity
Run Code Online (Sandbox Code Playgroud)
我尝试将代码放在isAdded()方法中以检查片段当前是否已添加到其活动中但仍然很少出现此错误.我不明白为什么我仍然会收到此错误.我怎么能阻止它?
它在线上显示错误 -
cameraInfo.setId(getResources().getString(R.string.camera_id));
Run Code Online (Sandbox Code Playgroud)
下面是我正在制作的示例api调用.
SAPI.getInfo(getActivity(),
new APIResponseListener() {
@Override
public void onResponse(Object response) {
cameraInfo = new SInfo();
if(isAdded()) {
cameraInfo.setId(getResources().getString(R.string.camera_id));
cameraInfo.setName(getResources().getString(R.string.camera_name));
cameraInfo.setColor(getResources().getString(R.string.camera_color));
cameraInfo.setEnabled(true);
}
}
@Override
public void onError(VolleyError error) {
mProgressDialog.setVisibility(View.GONE);
if (error instanceof NoConnectionError) {
String errormsg = getResources().getString(R.string.no_internet_error_msg);
Toast.makeText(getActivity(), errormsg, Toast.LENGTH_LONG).show();
}
}
});
Run Code Online (Sandbox Code Playgroud) android illegalstateexception android-fragments android-activity android-volley
众所周知,许多Android应用在首次Activity关注之前会非常简短地显示白屏.在以下情况中会出现此问题:
扩展全局Application类并在其中执行主要初始化的Android应用程序.的Application
对象总是第一之前创建Activity(可在调试程序观察的事实),所以这是有意义的.这是我案件延误的原因.
在启动画面之前显示默认预览窗口的Android应用程序.
设置android:windowDisablePreview = "true"显然在这里不起作用.我也不能Theme.Holo.NoActionBar像这里描述的那样将启动画面的父主题设置为,因为[不幸的是]我的启动画面使用了一个ActionBar.
同时,不扩展Application课程的应用程序在启动时不会显示白屏.
事实上,理想情况下,在Application对象中执行的初始化需要在显示第一个之前进行Activity.所以我的问题是,如何在不使用Application对象的情况下在应用启动时执行这些初始化?可能是使用了Thread或者Service,我想?
这是一个值得思考的有趣问题.我不能以通常的方式绕过它(通过设置NoActionBar主题),因为可悲的是我的Splash屏幕实际上ActionBar由于一些无关的原因.
注意:
我已经提到了以下问题:
参考文献:
我正在使用一个RecyclerView并从API获取对象,批量为十.对于分页,我使用EndlessRecyclerOnScrollListener.
一切正常.现在剩下的就是在列表底部添加一个进度微调器,同时由API提取下一批对象.以下是Google Play商店应用的屏幕截图,其中显示了以下ProgressBar内容RecyclerView:
问题是,在获取下一批对象时,既RecyclerView没有EndlessRecyclerOnScrollListener内置支持也没有显示ProgressBar底部的内置支持.
我已经看到了以下答案:
1. 将不确定的ProgressBar页脚放在RecyclerView网格中.
2. 添加项目到无尽的滚动RecyclerView与ProgressBar在底部.
我不满意这些答案(由同一个人).这涉及null 在用户滚动时中途将对象拴入数据集中,然后在下一批次交付后将其取出.它看起来像是一个黑客,可以回避主要问题,可能会或可能不会正常工作.它会在列表中引起一些刺耳和失真
使用SwipeRefreshLayout不是解决方案.SwipeRefreshLayout涉及从顶部拉取以获取最新的项目,并且它无论如何都不显示进度视图.
有人可以为此提供一个很好的解决方案吗?我有兴趣知道Google是如何为自己的应用程序实现此功能的(Gmail应用程序也有此功能).是否有任何文章详细显示?所有的答案和评论将不胜感激.谢谢.
其他一些参考:
1. 分页RecyclerView.(精湛的概述......)
2. RecyclerView页眉和页脚.(更多相同......)
android android-listview android-progressbar android-5.0-lollipop android-recyclerview
我有一个多语言的应用程序与主要语言英语和第二语言阿拉伯语.
如文档中所述,
android:supportsRtl="true"在清单中添加了.left和right属性start,并end分别.strings-ar(和其他资源类似).以上设置正常.改变后的Locale到ar-AE,阿拉伯文字和资源都正确地显示在我的活动.
但是,每次我导航到
ActivityaWebView和/或a时WebViewClient,语言环境,文本和布局方向都会突然恢复为设备默认值.
进一步提示:
Activity有a WebView和/或a WebViewClient(并且我有几个)时才会发生语言环境的突然转变.它不会发生在任何其他活动上.Android 7.0具有多语言环境支持,允许用户设置多个默认语言环境.因此,如果我将主要区域设置为Locale.UK:
然后在导航到时
WebView,语言环境从更改ar-AE为en-GB.
Android 7.0 API更改:
如API更改列表中所示,API 24中的以下类中添加了与语言环境相关的新方法:
Locale:
Configuration:
但是,我正在使用API 23构建我的应用程序,并且我没有使用任何这些新方法.
此外......
问题也出现在Nexus …
android locale android-webview android-7.0-nougat android-chrome
我正在处理动作菜单项及其溢流项目这是我的 main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_search"
android:icon="@drawable/search"
android:title="@string/start_new_project"
app:showAsAction="always" />
<item
android:id="@+id/menu_dts_overflow"
android:icon="@drawable/ic_action_overflow_round"
android:orderInCategory="11111"
android:title="Service"
app:showAsAction="always">
<menu>
<item
android:id="@+id/menu_newProject"
android:icon="@drawable/newproject"
android:title="@string/start_new_project"
app:showAsAction="never" />
<item
android:id="@+id/menu_help"
android:icon="@drawable/help"
android:title="Service Tasks"
app:showAsAction="never" />
<item
android:id="@+id/menu_signOut"
android:icon="@drawable/signout"
android:title="@string/menusignout"
app:showAsAction="never" />
</menu>
</item>
Run Code Online (Sandbox Code Playgroud)
我试图构建一个搜索项和溢出项,您可以在上面的代码中看到.我是Action栏目菜单项目的新手,所以我尝试了Google,并且能够让它按照我的需要运行.
在这里我还要知道一件事.
1.什么是orderInCategory一些数字,使用了什么..?
我刚刚下载了Android SDK.下载SDK Manager中的所有软件包将花费太多时间.所以我想知道是否应该取消选择除最新平台之外的所有平台.或者我需要所有平台?提前致谢.
我刚刚在Android SDK Manager中将Google Play服务更新到最新版本 - 23.接下来,我将项目中的依赖项更新为:
com.google.android.gms:play-services-gcm:8.3.0
但我得到了:
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
Found com.google.android.gms:play-services-gcm:8.3.0, but version 8.1.0 is needed
:app:processDebugGoogleServices FAILED
Error:Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict.
Run Code Online (Sandbox Code Playgroud)
怎么了?你有这个问题吗?
android google-play-services android-studio android-gradle-plugin
我有以下代码:
MainActivity.java
package com.erc.library;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import com.erc.sayeghlibrary.adapter.TabsPagerAdapter;
public class MainActivity extends FragmentActivity implements
ActionBar.TabListener {
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = { "Stories", "Dictionaries", "eBooks"};
@Override
protected …Run Code Online (Sandbox Code Playgroud) java android android-lifecycle android-fragments android-viewpager
谷歌已经为Android开发者发布了针对Android Studio 2.1 的新JACK编译器测试版.
我的问题是,我们如何使用JACK为APK进行模糊处理?下面的文章说JACK 本地执行模糊处理并且不需要Proguard:
以下文章说JACK使用Proguard配置文件(即.pro文件)来执行混淆:
它也说
在此过程中,Jack还处理任何请求的代码缩小(缩小和/或混淆).
这到底是什么意思?我们是否必须使用该minifyEnabled选项并定义.pro包含Proguard选项的文件?
综上所述:
我们究竟如何与JACK实现混淆?我们是否可以绕过Proguard的使用,或者Proguard在混淆过程中扮演事实上的角色,即使我们使用JACK编译?
JACK目前是否支持混淆,是否可以在Android Studio的稳定(即非beta/canary)版本中使用?
注意:
我已经提到了以下帖子:
进一步参考:
更新:
android android-sdk-tools android-studio android-jack-and-jill android-proguard
我想知道是否可以在没有支持库的情况下使用FragmentStatePagerAdapter类或其等价物?
我知道如何使用本机片段代替支持库中的那些片段,而许多其他类具有类似的等价物,但我找不到应该使用什么而不是这个类.
我基本上想扩展它在我的适配器中使用它像这样
public class ImageAdapter extends FragmentStatePagerAdapter {...
Run Code Online (Sandbox Code Playgroud) java android android-fragments android-viewpager android-support-library