发送阵列意图不同的包 [英] Sending array with Intent to different package

查看:111
本文介绍了发送阵列意图不同的包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题与数组中的意图。我想一个矩形阵列发送到另一个包。我下面的<一个href=\"http://www.anddev.org/view-layout-resource-problems-f27/how-can-i-pass-multidimensional-string-array-two-activities-t9259.html\"相对=nofollow>本教程。不幸的是,我仍然有意图的一个问题。所以,我有类 ActivityToSend 。我想 storePrintIMC 发送到不同包装的另一个类(样品preferenceActivity )。

I have problem with an Intent for an array. I want to send an rectangular array to another package. I'm following this tutorial. Unfortunately, I still have a problem with the Intent. So I have the class ActivityToSend. I want to send storePrintIMC into another class (SamplePreferenceActivity) of a different package.

ActivityToSend 类:

public class ActivityToSend extends Activity {
    private Activity activity;
    private ArrayList<String[]> data;
    private static LayoutInflater inflater = null;
    public String[] inkLevels = new String[5];
    View message;
    String [][] storePrintIMC= new String [4][4];
    public static final String ARRAYS_COUNT = "com.Status.App.ARRAYS_COUNT";
    public static final String ARRAY_INDEX = "com.Status.App.ARRAY_INDEX"; 

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final String data[][] = storePrintIMC; 
        Bundle bundle = new Bundle();
        int count = data.length; 
        bundle.putInt(ARRAYS_COUNT, count); 
        for (int i = 0; i < count; i++)
        { 
            bundle.putStringArray(ARRAY_INDEX + i, data[i]); 
        } 
        Intent intent = new Intent(this, SamplePreferenceActivity.class); 
        intent.putExtras(bundle);

        startActivity(intent);
    }
}

有关在不同包中的第二个活动我使用:

For the second activity in the different package I use:

public class SamplePreferenceActivity extends PreferenceActivity {    
    private static final int DIALOG_READ_ME = 1;
    public String[] inkLevels = new String[5];

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            int count = bundle.getInt(ActivityToSend.ARRAYS_COUNT, 0);

            ArrayList<String[]> arrays = new ArrayList<String[]>(count);

            for (int i = 0; i < count; i++)
                arrays.add(bundle.getStringArray(ActivityToSmartWatch.ARRAY_INDEX + i));

            String[][] data = arrays.toArray(new String[][]{});
        }
    }
}

我也做了一些改变与Android清单。对于第二个包,我把:

I also made some changes with the Android manifest. For the second package, I put:

<activity android:name=".SamplePreferenceActivity " android:label="@string/preference_activity_title">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.PrinterStatus.AppLab.SamplePreferenceActivity " /> 
  - <intent-filter>
        <action android:name="android.intent.action.MAIN" /> 
    </intent-filter>
</activity>
<activity android:name="com.sonyericsson.extras.liveware.extension.controlsample.SamplePreferenceActivity" android:parentActivityName="com.PrinterStatus.AppLab.ActivityToSend" /> 
<service android:name="com.sonyericsson.extras.liveware.extension.controlsample.SampleExtensionService" /> 

我在第一时间拿到包的错误:

I get an error in the first package in:

Intent intent = new Intent(this, SamplePreferenceActivity.class);

我不知道我有什么改变。你有什么想法?

I don't know what I have to change. Do you have any idea?

推荐答案

由于样品preferenceActivity 是在不同的包,你需要导入类到 ActivityToSend 。这就像任何其他进口。从什么在你的清单来看,你需要把这个近 com.PrinterStatus.AppLab.ActivityToSend.java 的顶部(与其他导入语句):

Since SamplePreferenceActivity is in a different package, you need to import the class into ActivityToSend. It's just like any other import. Judging from what's in your manifest, you need to put this near the top of com.PrinterStatus.AppLab.ActivityToSend.java (with the other import statements):

import com.sonyericsson.extras.liveware.extension.controlsample.SamplePreferenceActivity;

如果您使用的是Eclipse,你也许可以自动解决进口使用Ctrl-Shift-O组合。

If you're using Eclipse, you can probably resolve the import automatically using ctrl-shift-O.

这篇关于发送阵列意图不同的包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆