Android 一个活动/窗口如何获取另一个活动/窗口的文本?

Android 一个活动/窗口如何获取另一个活动/窗口的文本?,android,Android,我想制作一个实时字典应用程序。 一个活动/窗口可以获取另一个活动/窗口的文本吗? 可能吗? 另外,此应用程序适用于手机中的所有其他应用程序,因此我无法向其他应用程序插入代码。我的意思是在没有目标应用程序帮助的情况下获取文本。当两个应用程序运行时,用户触摸其中一个应用程序,另一个应用程序将获得被触摸的文本。活动1。 //Create 1 Bundle and send with Intent Bundle sendBundle = new Bundle(); sendBundle.putLong(

我想制作一个实时字典应用程序。

一个活动/窗口可以获取另一个活动/窗口的文本吗?

可能吗?


另外,此应用程序适用于手机中的所有其他应用程序,因此我无法向其他应用程序插入代码。我的意思是在没有目标应用程序帮助的情况下获取文本。当两个应用程序运行时,用户触摸其中一个应用程序,另一个应用程序将获得被触摸的文本。

活动1。

//Create 1 Bundle and send with Intent
Bundle sendBundle = new Bundle();
sendBundle.putLong("value", value);

// Intent to start Activity2 và and attach sendBundble
Intent i = new Intent(Activity1.this, Activity2.class);
i.putExtras(sendBundle);
    startActivity(i);

//exit Activity1
finish();
活动2.

Bundle receiveBundle = this.getIntent().getExtras();
final long receiveValue = receiveBundle.getLong("value");

receiveValueEdit.setText(String.valueOf(receiveValue));

Intent i = new Intent(Activity2.this, Receiver.class);
i.putExtra("new value", receiveValue - 10);
谢谢你,瓦伦。你可以用两种方法来做。 一种是从bundle中获取所需的值,另一种是使用SharedReferences

//使用束

在第一个活动中-

    String user_id = "abcd";
    Intent intent_msg = new Intent(this, 2nd activity.class);
    Bundle bundle_msg = new Bundle();
    bundle_msg.putString("user_id", user_id);
    intent_msg.putExtras(bundle_msg);
    startActivity(intent_msg);
在第二次活动中-

    String user_id = "abcd";
    Intent intent_msg = new Intent(this, 2nd activity.class);
    Bundle bundle_msg = new Bundle();
    bundle_msg.putString("user_id", user_id);
    intent_msg.putExtras(bundle_msg);
    startActivity(intent_msg);
//内部onCreate

    Bundle bundle = this.getIntent().getExtras();
    String user_id = bundle.getString("user_id");
//使用SharedReference

第一项活动-

    Editor editor= getSharedPreferences("userId", 0).edit();
    editor.putString("userId", user_id);
    editor.commit();
    SharedPreferences pref = getSharedPreferences("userId", 1);
    String user_id = pref.getString("userId", "");
第二项活动-

    Editor editor= getSharedPreferences("userId", 0).edit();
    editor.putString("userId", user_id);
    editor.commit();
    SharedPreferences pref = getSharedPreferences("userId", 1);
    String user_id = pref.getString("userId", "");

试试看。

您是否找到了从其他应用程序/活动获取触摸文本的解决方案?