how to stop the Thread in view class

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how to stop the Thread in view class

Postby zero_androider » Thu Feb 11, 2010 4:49 am

hi,all!
i start a Thread in a view class when the activity contain this view be onpened,in that ,i set a flag to control the thread,and i layout the applicationview like
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:call="http://schemas.android.com/apk/res/com.zero.launcher"
android:background="@drawable/background1">
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HI,ALL DIALING"
></TextView>
<com.zero.launcher.MyView
android:id="@+id/gifView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"
android:scaleType="center"
android:layout_x="20px"
android:layout_y="100px"
>
</com.zero.launcher.MyView>
<ImageButton
android:id="@+id/btn1"
android:layout_width="100px"
android:layout_height="60px"
android:layout_x="50px"
android:layout_y="150px"
></ImageButton>
</AbsoluteLayout>
i want to stop the thread when the activity backgroud or destroyed.
but actually in my application the thread still opened for i can not change the flag ,
i want to know how to change the flag in the view class by the status of the view is changed.
thanks
my Gmail is :junjy2010@gmail.com
zero_androider
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Feb 04, 2010 11:09 am

Top

Postby pmws » Sat Feb 13, 2010 12:27 pm

I m not quite sure if i understand you corectly. But I think you could try to close the Thread in the onDestroy and onStop method.

Something like :


@Override
public void onDestroy() {
yourThreadName.join();
yourThreadName.stop();
}
(gets called when the Activity is destroyed)


@Override
public void onStop() {
yourThreadName.join();
yourThreadName.stop();
}
(Called when the activity is no longer visible to the user)
pmws
Developer
Developer
 
Posts: 37
Joined: Thu Sep 24, 2009 12:23 pm

Postby element56 » Sun Feb 14, 2010 9:09 pm

try this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3. public void onPause() {
  4.  
  5.      yourThread.interrupt();
  6.  
  7. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


You'll have to catch the InterruptedException that gets thrown in your thread
element56
Freshman
Freshman
 
Posts: 7
Joined: Sun Feb 14, 2010 8:52 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests