- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试将字符串从主要 Activity 传递到从服务扩展的另一个类。我从 main 的 onCreate 方法发送它:
Intent phoneintent = new Intent(MainActivity.this, AlarmServic.class);
String phoneN = phoneNumber.getText().toString();
phoneintent.putExtra("PhoneNumber",phoneN );
startActivity(phoneintent);
并在 onStartCommand 方法中接收它,如下所示:
String phone = getIntent().getExtras().getString("PhoneNumber");
但它给了我红色的 getIntent() 并且无法解决它
有什么帮助吗?
最佳答案
Intent phoneintent = new Intent(MainActivity.this, AlarmServic.class);
String phoneN = phoneNumber.getText().toString();
phoneintent.putExtra("PhoneNumber",phoneN );
startService(phoneintent);// If its a Service
并在服务中检索为
public int onStartCommand(Intent intent, int flags, int startId) {
String phoneNumber= intent.getStringExtra("PhoneNumber");
...........
}
关于java - getIntent()用红色写成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36983535/
您好,我正在尝试将 Activity 更改为 fragment ,以便将其添加到滑动布局中,我想我快完成了(除非任何人都可以在我的代码中看到任何其他错误)但我找不到在任何地方解决我的问题,它说'get
我有点困惑为什么在 RoutineRetrieved 函数中分配 ACTIVITYIMAGE 时使用 result.getInt(2) 并在分配 SLOT 时使用 result.getInt(3)..
我想从第二个 Activity 中获取一个值,以便在单独的类(fragmentPageAdapter)中使用它。首先,使用 Intent.putExtra(key_name, string) 将这个值
我有一个如下定义的 oracle 表: create table image_table_test (id number primary key, image ordsys.ordimage); 当我
/* * GETINTDRIVER -- program to call an integer reading function * * Compiling: put the getint fu
学习如何制作 Android 应用程序,我完成了这个教程。图的摘要在这里: http://sketchytech.blogspot.com/2012/10/android-simple-user-in
我是 android 应用程序的新手。我正在开发一个聊天应用程序。我使用了 RecyclerView 和内部 recyclerview 适配器,我在 Activity 开始时传递一个数据 下面是我的代
我正在通过这样的 Intent 从另一个 Activity 中获取 byteArray: if (view == null) { view = new ImageVie
我正在尝试将字符串从主要 Activity 传递到从服务扩展的另一个类。我从 main 的 onCreate 方法发送它: Intent phoneintent = new Intent(MainAc
我的程序由一个 MainActivity 和两个 fragment Activity 组成。我需要一个 fragment 从用户那里获取一个字符串值并将其传递给第二个 fragment 。 我正在努力
我不明白为什么我们使用方法 getIntent()。 因为,当我们需要那个方法时,我们可以使用方法onActivityResult()。 但是通过使用方法getIntent(),它可能会导致NullP
以下方法在 Activity 打开时返回空指针异常。有人知道为什么吗?调用 getIntent() 时是否与不存在 Intent 有关? 如有任何帮助,我们将不胜感激。 日志: 04-21 15:38
在 getView() 方法中,我想调用 getIntent()。在不开始新 Activity 的情况下如何实现这一目标。像这样的getView方法 public View getView(final
带你来看看mybatis为什么报"Invalid value for getInt()"这个错误。 背景 使用mybatis遇到一个非常奇葩的问题,错误如下: Cause: org.apache.ib
Firebase 提供以下方法: getBoolean() getByteArray() getDouble() getLong() getString() https://firebase.goog
此代码启动 Activity : Intent intent = new Intent(context, GameActivity.class); intent.putExtra("load"
我有一个问题,此代码仅返回默认值 -1。我尝试调试,它有值(value),所以我不知道为什么它总是返回-1。 private static final String KEY_CATEGORY_ID =
我在 app_restrictions.xml 中有这个: 现在,如果我想阅读它,我会得到 > java.lang.ClassCastException: java.lang.String cann
我有这个方法: public String givenCheckmark(String name, String date) { SQLiteDatabase db = Cache.open
在这里,resultSet.getInt() 不起作用,但我不知道我的代码出了什么问题。 我想增加列的值(名称为变量“出勤”)。使用 SELECT 语句我想读取当前值,通过使用 UPDATE 我想将相
我是一名优秀的程序员,十分优秀!