最近我看到了这个——Most data sources already provide main-safe APIs like the suspend method calls provided by Room or Retrofit. Your repository can take advantage of these APIs when they are available.
这是什么意思?调度员是否在 Retrofit 和 Room 的幕后Dispatcher.IO?或者我需要在提出请求时明确提及这一点吗?谢谢。
withContext(Dispatchers.IO) {
// Some retrofit call or room query
}
Run Code Online (Sandbox Code Playgroud) 我正在检索 a json,当我使用 将其转换为列表时gson,应用程序崩溃了。已proguard打开,问题就在那里。
fun getQuestions(): List<Question>? {
val json = getQuestionsJsonData()
return GsonBuilder().create().fromJson(
json,
object : TypeToken<List<Question>?>() {}.type
)
}
Run Code Online (Sandbox Code Playgroud)
由于我混淆了我的代码,我无法看到crashlog in logcat,所以我将其发送到firebase crashlitycs. 错误消息是 -Caused by java.lang.RuntimeException: Missing type parameter.
也许Question类型被混淆了或者发生了类似的事情。我的混淆器文件:
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
#Serialized
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final …Run Code Online (Sandbox Code Playgroud) 我是科特林初学者。我尝试创建一个每 2 秒重复一次的任务。所以我创造了这样的东西。
val handler = Handler()
handler.postDelayed(Runnable {
// TODO - Here is my logic
// Repeat again after 2 seconds
handler.postDelayed(this, 2000)
}, 2000)
Run Code Online (Sandbox Code Playgroud)
但在 postDelayed(this) 中它给出了错误 - required Runnable!, found MainActivity。我什至尝试过,this@Runnable但没有成功。
但是当我像这样编写相同的函数时,它就可以工作了
val handler = Handler()
handler.postDelayed(object : Runnable {
override fun run() {
// TODO - Here is my logic
// Repeat again after 2 seconds
handler.postDelayed(this, 2000)
}
}, 2000)
Run Code Online (Sandbox Code Playgroud)
那么为什么this关键字在第一个函数中不起作用,但在第二个函数中却很好呢?
在我的应用程序中,我使用了 firebase crashlytics。我的代码被混淆了。我在 proguard 中添加了这行代码,以便对我的堆栈跟踪进行反混淆处理。
-keepattributes SourceFile,LineNumberTable # Keep file names and line numbers.
-keep public class * extends java.lang.Exception # Optional: Keep custom exceptions.
Run Code Online (Sandbox Code Playgroud)
现在它可以对我的堆栈跟踪进行反混淆,但不能对崩溃描述进行反混淆。它仍然抛出例如java.lang.NullPointerException: Attempt to invoke virtual method 'myapp.shared.Repository g.a.e.e.u(java.lang.Class)' on a null object reference。有没有办法让 crashlytics 也去混淆我的崩溃描述,而不仅仅是堆栈跟踪?
在下面的代码中,我有一个模块,我在其中调用@InstallIn(SingletonComponent::class). singleton因此,该模块的范围是应用程序范围或单例范围))如果我将在模块内提供某些内容,我是否还需要注释该函数?
但是我没有得到想要的结果。我需要得到这个:
您会看到我已经对该专业进行了分组,并且所有专业都有其自己的图标。现在,我将包括我的recyclerView代码。我要如何在图片中喜欢?如果我做错了什么,请告诉我,不要拒绝投票。
这是项类。
public class Rec_Items {
private int image;
private String fullName;
private String profession;
public Rec_Items(int image, String fullName, String profession) {
this.image = image;
this.fullName = fullName;
this.profession = profession;
}
public int getImage() {
return image;
}
public String getFullName() {
return fullName;
}
public String getProfession() {
return profession;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,这里将adapter与它的ViewHolder。
public class SupportersAdapter extends RecyclerView.Adapter<SupportersAdapter.MyViewHolder> {
Context context;
List<Supporters_item> list = new ArrayList<>();
public …Run Code Online (Sandbox Code Playgroud) 我正在创建授权应用程序,我正在使用Retrofit 2.当我正在进行调用时,这将转到onFailure方法并获得异常
"javax.net.ssl.SSLException: Connection closed by peer"
但问题是,昨天这很有效.今天它给了例外.我在互联网上找到一些SSLException - 在Android 4.x版本上由peer关闭的连接,或者如何使用Retrofit添加TLS v 1.0和TLS v.1.1,但这对我没有帮助.任何想法如何解决它.在后端TLS1.2启用.
public class RegistrationFragment extends BaseFragment {
View mainView;
ApiClient apiClient = ApiClient.getInstance();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mainView = inflater.inflate
(R.layout.registration_fragment, container, false);
//Calling the authorization method
registerCall();
}
});
return mainView;
}
//User authorization method
public void registerCall() {
Call<ResponseBody> call = apiClient.registration(supportopObj);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) …Run Code Online (Sandbox Code Playgroud) 我的操作系统是windows。所以在我的电脑中有一种名为“Ayuthaya.ttf”的字体(这不是 Windows 默认字体)。
我想在android studio中使用这个字体。但在 android studio 设置的字体列表中我找不到该字体。
但在 IntelliJ 的设置中,字体是可见的。那么我该如何修复它呢?
我正在使用Hilt与Jetpack Compose.
@HiltViewModel
class HomeViewModel @Inject constructor(
private val homeRepository: HomeRepository
): ViewModel() {
fun getCarDetails(): Car {
return homeRepository.getCarDetails()
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我注入回购协议的方式。
@Module
@InstallIn(SingletonComponent::class)
abstract class DataModule {
@Binds
@Singleton
abstract fun bindHomeRepository(
homeRepository: HomeRepositoryImpl,
): HomeRepository
}
Run Code Online (Sandbox Code Playgroud)
这就是我的可组合项。
@Composable
fun HomeScreen(viewModel: HomeViewModel = viewModel()) {
val carData = viewModel.getCarDetails()
Column(
Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
TopBar(carData = carData, modifier = Modifier)
CarImage(carData = carData, modifier = Modifier)
}
}
Run Code Online (Sandbox Code Playgroud)
我用 注释了我Activity的 …

我有一个recycleView(见图).你看也有2个按钮.这是布局file.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@color/white">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_marginLeft="10dp"
android:id="@+id/main_picture"
android:layout_width="45dp"
android:layout_height="50dp"
android:src="@drawable/pfl_img"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/main_picture"
android:layout_marginRight="5dp"
android:layout_marginLeft="10dp"
android:id="@+id/relativeLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edem Palonik"
android:textSize="17sp"
android:id="@+id/textName"
android:textColor="@color/black"
android:layout_above="@+id/textDescription"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profession and ..."
android:textColor="@color/black"
android:textSize="17sp"
android:id="@+id/textDescription"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="20dp"
android:layout_height="18dp"
android:layout_marginTop="2dp"
android:layout_below="@+id/textDescription"
android:id="@+id/historyIcon"
android:layout_alignParentStart="true" />
<TextView
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/date"
android:textSize="14sp"
android:text="17/12/2017/13:46"
android:layout_marginTop="2dp"
android:layout_below="@+id/textDescription"
android:layout_toEndOf="@+id/historyIcon" />
</RelativeLayout>
<Button
android:id="@+id/call_button"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginRight="10dp"
android:background="@drawable/call_img"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/sms_button" />
<Button
android:id="@+id/sms_button"
android:layout_width="37dp"
android:layout_height="32dp" …Run Code Online (Sandbox Code Playgroud) android ×9
kotlin ×4
java ×3
dagger-hilt ×2
retrofit ×2
android-room ×1
crashlytics ×1
firebase ×1
fonts ×1
gson ×1
handler ×1
obfuscation ×1
proguard ×1
runnable ×1
sslexception ×1
tls1.2 ×1
typetoken ×1
viewmodel ×1