我在选项卡视图中启动新活动时遇到错误

发布于 2024-10-06 01:55:34 字数 3893 浏览 0 评论 0原文

在我的应用程序中,每当我尝试在 onclick 列表视图触摸事件上启动新活动时,我都会在一个选项卡的 Tabview 内显示列表。我想在 webview 中开始一个新的活动。

showNewsListView.setAdapter(listAdapter);
 showNewsListView.setOnItemClickListener(new OnItemClickListener(){
  public void onItemClick(AdapterView<?> arg0, View arg1, int position,
        long arg3) {
            Log.v("status ","tab on   position"+position);
           Intent myIntent = new Intent(BizTab.this, MainView.class);
           startActivity(myIntent);

          }
          });

 getUrlData(baseUrl);

 }

如果我运行这么多代码,应用程序就会崩溃,所以我只是找到了它的解决方案,我应该异步启动一个新活动,所以现在,我正在这样做:

    showNewsListView.setAdapter(listAdapter); 
    showNewsListView.setOnItemClickListener(new OnItemClickListener(){
     public void onItemClick(AdapterView arg0, View arg1, int position, long arg3) { Log.v("status ","tab on position"+position);

         new ShowFullNews().execute();
      }
      });
 getUrlData(baseUrl);

 }`

`showNewsListView.setAdapter(listAdapter);
 showNewsListView.setOnItemClickListener(new OnItemClickListener(){
  public void onItemClick(AdapterView<?> arg0, View arg1, int position,
        long arg3) {
            Log.v("status ","tab on   position"+position);

         new ShowFullNews().execute();
      }
      });
 getUrlData(baseUrl);

 }`

然后我的代码也会崩溃,并且不会给出错误,只是给出两个警告。

如果我在 onTouch 和 postexecute 两个地方启动一个新活动,那么我的代码可以正常工作,但这里它首先显示屏幕,然后自动刷新该屏幕,这看起来不太好。那么如何避免呢。请帮我。

我的工作代码是:

public void onItemClick(AdapterView<?> arg0, View arg1, int position,
        long arg3) {
            Log.v("status ","tab on   position"+position);

            //set bundle to send data into other activity
            b.putInt("total", 10);
            b.putInt("position",position);
            b.putStringArray("allurls", allsNewsUrls);
            b.putString("returnname", "BizTab");
            b.putString("footertext","Biz");
            b.putInt("tabid", 3);

           Intent myIntent = new Intent(BizTab.this, MainView.class);
            myIntent.putExtras(b);
            startActivity(myIntent);
            new ShowFullNews().execute();
      }
      });

 protected void onPostExecute(Long result) { try { 
   Intent myIntent2 = new Intent(BizTab.this, MainView.class);

 startActivity(myIntent2);


} catch (Exception e) {
 Log.v("error","error in starting new activity");
 e.printStackTrace();
}

  }`

日志生成,我的应用程序自动关闭。

12-07 11:55:18.684: WARN/InputManagerService(72): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44067388
12-07 11:55:20.792: VERBOSE/status(419): tab on   position0
12-07 11:55:20.814: INFO/ActivityManager(72): Starting activity: Intent { cmp=org.nuvus/.MainView (has extras) }
12-07 11:55:20.872: DEBUG/PhoneWindow(419): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@43ea45d8 has no id.
12-07 11:55:21.023: VERBOSE/status(419): mainView oncreate called
12-07 11:55:21.452: VERBOSE/status(419): onStartcalled
12-07 11:55:21.962: INFO/ActivityManager(72): Displayed activity org.nuvus/.MainView: 1072 ms (total 1072 ms)
12-07 11:55:22.082: INFO/AndroidRuntime(419): AndroidRuntime onExit calling exit(0)
12-07 11:55:22.173: INFO/ActivityManager(72): Process org.nuvus (pid 419) has died.
12-07 11:55:22.183: INFO/WindowManager(72): WIN DEATH: Window{43fe6f30 org.nuvus/org.nuvus.Main paused=true}
12-07 11:55:22.202: INFO/WindowManager(72): WIN DEATH: Window{440f9620 org.nuvus/org.nuvus.MainView paused=false}
12-07 11:55:22.283: INFO/UsageStats(72): Unexpected resume of com.android.launcher while already resumed in org.nuvus
12-07 11:55:22.303: WARN/InputManagerService(72): Got RemoteException sending setActive(false) notification to pid 419 uid 10032

请帮我...

In my application, I am showing List inside the Tabview in one tab, whenever I am trying to start a new activity on onclick a list view touch event. I want to start a new activity in webview.

showNewsListView.setAdapter(listAdapter);
 showNewsListView.setOnItemClickListener(new OnItemClickListener(){
  public void onItemClick(AdapterView<?> arg0, View arg1, int position,
        long arg3) {
            Log.v("status ","tab on   position"+position);
           Intent myIntent = new Intent(BizTab.this, MainView.class);
           startActivity(myIntent);

          }
          });

 getUrlData(baseUrl);

 }

if I run this much code app is crashing so I just find its solution that I should start a new activity asynchronously so now, I m doing this:

    showNewsListView.setAdapter(listAdapter); 
    showNewsListView.setOnItemClickListener(new OnItemClickListener(){
     public void onItemClick(AdapterView arg0, View arg1, int position, long arg3) { Log.v("status ","tab on position"+position);

         new ShowFullNews().execute();
      }
      });
 getUrlData(baseUrl);

 }`

`showNewsListView.setAdapter(listAdapter);
 showNewsListView.setOnItemClickListener(new OnItemClickListener(){
  public void onItemClick(AdapterView<?> arg0, View arg1, int position,
        long arg3) {
            Log.v("status ","tab on   position"+position);

         new ShowFullNews().execute();
      }
      });
 getUrlData(baseUrl);

 }`

Then also my code is crashing and not giving error just giving two warnings.

If I start a new activity in both places onTouch and post execute then my code is working but here it first show screen and then its went automatically and refresh that screen, that is not looking good. so how to avoid it. Please help me.

My working code is:

public void onItemClick(AdapterView<?> arg0, View arg1, int position,
        long arg3) {
            Log.v("status ","tab on   position"+position);

            //set bundle to send data into other activity
            b.putInt("total", 10);
            b.putInt("position",position);
            b.putStringArray("allurls", allsNewsUrls);
            b.putString("returnname", "BizTab");
            b.putString("footertext","Biz");
            b.putInt("tabid", 3);

           Intent myIntent = new Intent(BizTab.this, MainView.class);
            myIntent.putExtras(b);
            startActivity(myIntent);
            new ShowFullNews().execute();
      }
      });

 protected void onPostExecute(Long result) { try { 
   Intent myIntent2 = new Intent(BizTab.this, MainView.class);

 startActivity(myIntent2);


} catch (Exception e) {
 Log.v("error","error in starting new activity");
 e.printStackTrace();
}

  }`

The Log generating are and my app is closing automatically.

12-07 11:55:18.684: WARN/InputManagerService(72): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44067388
12-07 11:55:20.792: VERBOSE/status(419): tab on   position0
12-07 11:55:20.814: INFO/ActivityManager(72): Starting activity: Intent { cmp=org.nuvus/.MainView (has extras) }
12-07 11:55:20.872: DEBUG/PhoneWindow(419): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@43ea45d8 has no id.
12-07 11:55:21.023: VERBOSE/status(419): mainView oncreate called
12-07 11:55:21.452: VERBOSE/status(419): onStartcalled
12-07 11:55:21.962: INFO/ActivityManager(72): Displayed activity org.nuvus/.MainView: 1072 ms (total 1072 ms)
12-07 11:55:22.082: INFO/AndroidRuntime(419): AndroidRuntime onExit calling exit(0)
12-07 11:55:22.173: INFO/ActivityManager(72): Process org.nuvus (pid 419) has died.
12-07 11:55:22.183: INFO/WindowManager(72): WIN DEATH: Window{43fe6f30 org.nuvus/org.nuvus.Main paused=true}
12-07 11:55:22.202: INFO/WindowManager(72): WIN DEATH: Window{440f9620 org.nuvus/org.nuvus.MainView paused=false}
12-07 11:55:22.283: INFO/UsageStats(72): Unexpected resume of com.android.launcher while already resumed in org.nuvus
12-07 11:55:22.303: WARN/InputManagerService(72): Got RemoteException sending setActive(false) notification to pid 419 uid 10032

please help me...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若言繁花未落 2024-10-13 01:55:34

而不是:

Intent myIntent = new Intent(BizTab.this, MainView.class);
myIntent.putExtras(b);
startActivity(myIntent);

尝试使用:

Intent myIntent = new Intent(getBaseContext(), BizTab.this); <!-- or MainView.class-->
myIntent.putExtras(b);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);

Instead of:

Intent myIntent = new Intent(BizTab.this, MainView.class);
myIntent.putExtras(b);
startActivity(myIntent);

Try with:

Intent myIntent = new Intent(getBaseContext(), BizTab.this); <!-- or MainView.class-->
myIntent.putExtras(b);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文