小编Ste*_*nJo的帖子

Android 在应用程序购买中 - 服务连接已断开调试消息

当我尝试在我的应用程序中实现应用程序内购买时,我不断收到 -1 响应代码。我已经在我的游戏控制台中添加了一个产品。有什么帮助吗?

调试响应消息:D/LOG:服务连接已断开。

public class InAppPurchase extends AppCompatActivity {

private BillingClient billingClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_in_app_purchase);


    billingClient = BillingClient.newBuilder(this).setListener(new PurchasesUpdatedListener() {
        @Override
        public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> list) {

        }
    }).enablePendingPurchases().build();
    billingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(BillingResult billingResult) {
            if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                // The BillingClient is ready. You can query purchases here.
                Toast.makeText(InAppPurchase.this, "Its Okay!", Toast.LENGTH_SHORT).show();
            }
        }
        @Override
        public void onBillingServiceDisconnected() {
            // Try to restart the connection on the …
Run Code Online (Sandbox Code Playgroud)

android in-app-purchase

5
推荐指数
0
解决办法
1152
查看次数

RecyclerView适配器+数据绑定

好的,我正在尝试在我的 recyclerview 适配器中实现数据绑定,我需要帮助,因为我不知道具体如何实现?我正在尝试从我的 recyclerview 适配器中删除样板代码,这就是原因。检查我的代码如下:

custom_row(Recyclerview项目布局)

<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>
        <variable
            name="toDoData"
            type="com.jovanovic.stefan.tododemo.data.ToDoData" />
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="4dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/row_background"
            android:layout_width="match_parent"
            android:layout_height="120dp"
            android:background="@drawable/item_background"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <TextView
                android:id="@+id/title_txt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_marginTop="16dp"
                android:text="@{toDoData.title}"
                android:textColor="@color/darkGray"
                android:textSize="20sp"
                android:textStyle="bold"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/description_txt"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="16dp"
                android:maxLength="160"
                android:maxLines="3"
                android:text="@{toDoData.description}"
                android:textColor="@color/darkGray"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="@+id/title_txt"
                app:layout_constraintTop_toBottomOf="@+id/title_txt" />

        </androidx.constraintlayout.widget.ConstraintLayout>


    </androidx.constraintlayout.widget.ConstraintLayout>

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

待办事项数据

@Parcelize
@Entity(tableName = "todo_table")
data class ToDoData(
    @PrimaryKey(autoGenerate = true)
    var id: Int,
    var …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-recyclerview

5
推荐指数
1
解决办法
7659
查看次数

应用程序对带有 HILT 的 ViewModel 的依赖

我想知道如何使用 Hilt 将应用程序依赖项传递给 ViewModel?我尝试使用 AndroidViewModel,但无法成功。有人能帮我吗?一些简短的样本对我来说可能意义重大。

这是我的视图模型:

class MainViewModel @ViewModelInject constructor(
    private val application: Application,
    private val repository: Repository,
    @Assisted private val savedStateHandle: SavedStateHandle
) : ViewModel() {
Run Code Online (Sandbox Code Playgroud)

这是我的刀柄模块

@Module
@InstallIn(ApplicationComponent::class)
object DatabaseModule {

    @Singleton
    @Provides
    fun provideDatabase(
        @ApplicationContext context: Context
    ) = Room.databaseBuilder(
        context,
        MyDatabase::class.java,
        "my_database"
    ).build()

    @Singleton
    @Provides
    fun provideDao(database: MyDatabase) = database.myDao()

    @Singleton
    @Provides
    fun provideRepository(myDao: MyDao) = Repository(myDao)

    @Singleton
    @Provides
    fun provideApplicationContext() = MyApplication()

}
Run Code Online (Sandbox Code Playgroud)

其他一切都很好,但我收到了错误消息:

引起:java.lang.RuntimeException:无法创建类 com.example.example.viewmodel.MainViewModel 的实例 引起:java.lang.InstantiationException:java.lang.Class<com.example.example.viewmodel.MainViewModel> 有无零参数构造函数

android kotlin dagger-hilt

5
推荐指数
1
解决办法
5220
查看次数