Java getIntent,Can';我无法通过我的活动了解最新的意图

Java getIntent,Can';我无法通过我的活动了解最新的意图,java,android,android-intent,android-activity,Java,Android,Android Intent,Android Activity,我确信这是我理解意图的一个失败,但我有一个项目的可扩展列表视图,当我点击一个项目时,它会启动第一个项目确定,但每次之后,无论我点击哪个项目,它只会再次启动第一个项目。请求调试为OK,但收到的意图总是调试为发送第一个。在花了半天的时间在上面,谷歌让我失望了,我需要一些帮助 活动#1主要活动 <activity android:name="com.h17.gpm.ActivityToDoList" android:launchMode="singleInstan

我确信这是我理解意图的一个失败,但我有一个项目的可扩展列表视图,当我点击一个项目时,它会启动第一个项目确定,但每次之后,无论我点击哪个项目,它只会再次启动第一个项目。请求调试为OK,但收到的意图总是调试为发送第一个。在花了半天的时间在上面,谷歌让我失望了,我需要一些帮助

活动#1主要活动

<activity
        android:name="com.h17.gpm.ActivityToDoList"
        android:launchMode="singleInstance"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.h17.gpm.TODO" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</activity>
活动#2主要活动

<activity
        android:name="com.h17.gpm.ActivityToDoEdit"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.h17.gpm.TODO.EDIT" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</activity>
我从其他帖子中读到,getIntent返回第一个Intent,因此也尝试了

@Override
protected void onNewIntent(Intent intent){  
    Bundle extras = null;
    if(intent != null)
        extras = intent.getExtras();
    if (extras != null){ 
        action_id = extras.getLong("Action._ID");
        Log.d("ACTIVITYLAUNCHTEST", "Receive New Intent["+action_id+"]");
    }
    setIntent(intent);
}
我也在清单中尝试了很多意图标志和启动模式的组合,但在我的生命中,第一次总是以

Launch[1]
Receive[1]
第二次呢

Launch[2]
Receive[1]
从那时起,无论我发送什么值,活动都会以第一个值启动,1和onNewIntent似乎永远不会启动

生成意图的完整函数

private void loadLists(){
    ExpandableListView expandableList = (ExpandableListView) findViewById(R.id.expandableListViewToDoLists);
    expandableList.setClickable(true);
    adapter = new ActionListsExpandableAdapter(getApplicationContext());
    expandableList.setAdapter(adapter);
    expandableList.setOnChildClickListener(new OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

            Action a = (Action) parent.getExpandableListAdapter().getChild(groupPosition, childPosition);
            if (startedForResult){
                Intent data = new Intent();
                data.putExtra("Action._ID", a.get_ID());
                data.putExtra("Action.SUBJECT", a.getSUBJECT());
                setResult(RESULT_OK, data);
                finish();
            }else{
                ActionList al = (ActionList) parent.getExpandableListAdapter().getGroup(groupPosition);
                Intent launch = new Intent(ActivityToDoList.this, ActivityToDoEdit.class);
                launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
                launch.putExtra("Action._ID", a.get_ID());
                Log.d("ACTIVITYLAUNCHTEST", "Launching activity with intent for Action ID ["+a.get_ID()+"]");
                launch.putExtra("ActionList._ID", al.get_ID());
                launch.putExtra("ActionList.position", childPosition);
                startActivity(launch);
            }

            return false;
        }
    });
}

也许这对你来说是一个很好的参考。 在我看来,如果应用程序未被销毁,则会调用
onNewIntent(带有标志\u ACTIVITY\u SINGLE\u TOP)
like onCreate。希望对你有帮助。在我的情况下它对我有效

有关更多参考,请参阅

getExtras()返回可由putExtras()设置的捆绑包,这里您使用的是putExtra()。您好,Neet,可能我误解了,但我尝试使用I.getLongExtra(“Action.\u ID”,0);你能给我们看更多发送
意图的代码吗?谢谢,我已经添加了当你点击可扩展列表中的一个项目时运行的完整函数
get_ID()
返回什么?你一定是弄错了。
Launch[2]
Receive[1]
private void loadLists(){
    ExpandableListView expandableList = (ExpandableListView) findViewById(R.id.expandableListViewToDoLists);
    expandableList.setClickable(true);
    adapter = new ActionListsExpandableAdapter(getApplicationContext());
    expandableList.setAdapter(adapter);
    expandableList.setOnChildClickListener(new OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

            Action a = (Action) parent.getExpandableListAdapter().getChild(groupPosition, childPosition);
            if (startedForResult){
                Intent data = new Intent();
                data.putExtra("Action._ID", a.get_ID());
                data.putExtra("Action.SUBJECT", a.getSUBJECT());
                setResult(RESULT_OK, data);
                finish();
            }else{
                ActionList al = (ActionList) parent.getExpandableListAdapter().getGroup(groupPosition);
                Intent launch = new Intent(ActivityToDoList.this, ActivityToDoEdit.class);
                launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
                launch.putExtra("Action._ID", a.get_ID());
                Log.d("ACTIVITYLAUNCHTEST", "Launching activity with intent for Action ID ["+a.get_ID()+"]");
                launch.putExtra("ActionList._ID", al.get_ID());
                launch.putExtra("ActionList.position", childPosition);
                startActivity(launch);
            }

            return false;
        }
    });
}