getIntExtra()始终返回默认值

时间:2017-03-02 17:06:10

标签: java android android-intent int

我有两个不同的应用程序,AppA和AppB,我正在尝试从AppB向AppA发送一个int,但AppA中的getIntExtra()始终获得默认值0.

当前在AppA,gameRecords_str正在接收正确的字符串值,但我一直为gameCounter获取默认值0。出了什么问题?

APPB:

String query = "SELECT * FROM gameRecord";
Cursor mcursor = database.rawQuery(query, null);
int counter = mcursor.getCount();   // Find out the number of records found in database
System.out.println("Number of record : " + counter);

Intent sendCounter = new Intent();
sendCounter.setAction("com.joy.AppA.LAUNCH_IT");
sendCounter.putExtra("counter", counter);
startActivity(sendCounter);

String gameRecord_str;
int flag;

mcursor.moveToFirst();
if (mcursor != null) {
  if (mcursor.moveToFirst()) {
      do {

         String record = mcursor.getString(mcursor.getColumnIndex("record"));
         gameRecord_str = record;

         Intent i = new Intent();
         i.setAction("com.joy.AppA.LAUNCH_IT");
         i.putExtra("gameRecord", gameRecord_str);
         startActivity(i);

         } while (mcursor.moveToNext());

APPA:

Intent intent = getIntent();
int gameCounter = intent.getIntExtra("counter", 0); //Number of records from game AppB
System.out.println("gameCounter : " + gameCounter);

for (int i=0; i<=gameCounter; i++) {
String gameRecords_str = intent.getStringExtra("gameRecord");
System.out.println("Game record received from AppB : " + gameRecords_str);


在此先感谢您的帮助!

0 个答案:

没有答案