最近在android开发中,用到都是new Thread(){...}.start()这种方式.本来这样是可以,但是最近突然爆出Performing stop of activity that is not resumed 错误,google了一下发现是线程多次创建的问题: 多次使用上面的方式,会创建多个匿名线程.使得程序运行起来越来越慢. 因此,可以考虑使用一个Handler来启动一个线程,当该线程不再使用就删除,保证线程不会重复创建.一般会使用Handler handler = new Ha
在面试时候经常被问到多线程的相关问题: 今天在测试的时候发现下面的代码会抛出异常: java.lang.IllegalThreadStateException public static void main(String[] args)throws Exception{ Test_Thread temp = new Test_Thread(); Test_Thread temp1 = new Test_Thread(); Thread t = new Thread(temp); Thread t
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows.Forms; namespace Demo { static class Program { /// <summary> /// 用于判
本来想着用handlerpostdelay就可以实现,没想到演示后关闭应用居然报错. 后来想到是没有了activity. ((Activity)context).isFinishing() 可以传入context,再强转成activity.判断此acitvity是否存在,之后就可有去放心的弹出了. 通过sharedpreference判断是否购买. public class MyDialog { static SharedPreferences myShare; public sta
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Threading; namespace WindowsFormsApplication1 { static class Program { /// <summary> /// The main entry point for the application. /// </s
创建类Mutex.cs: using System; using System.Linq; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace Demo { public class Mutex { [DllImport("coredll.dll", EntryPoint = "CreateMutex", SetLas