现在的位置: 首页 > 综合 > 正文

2014年6月4日北京一公司电话面试总结

2017年12月22日 ⁄ 综合 ⁄ 共 2996字 ⁄ 字号 评论关闭

整个过程中,感觉自己的懂的东西不能很好的表达,归其原因,还是平时总结的比较少。而且基础特别重要。

其中对于三个问题做总结。

1,java连接数据库,

先用Class.forName("")加载驱动程序,Connection conn=DriverManager.getConnection(BDURL,DBUSER,DBPASS);

2,jsp两种跳转方式的区别

1.forward跳转: a.服务器端跳转,地址栏不改变; b.执行到跳转语句后马上无条件跳转,之后的代码不再执行(跳转之前一定要释放全部资源); c.request设置的属性在跳转后的页面仍可以使用; d.使用<jsp:param name="参数名" value="参数值" />传递参数。
2.response跳转: a.客户端跳转,地址栏改变; b.所有代码执行完毕后跳转; c.跳转后的页面不能使用上一个页面的request属性; d.使用地址重写传递参数(response.sendRedirect("URL?参数名=参数值"))。
3,启动service的两种不同方式。

1.Context.startService()方式启动 

①Context.startService()方式的生命周期: 启动时,startService –> onCreate() –> onStart()停止时,stopService –> onDestroy()如果调用者直接退出而没有停止Service,则Service 会一直在后台运行 Context.startService()方法启动服务,在服务未被创建时,系统会先调用服务的onCreate()方法,接着调用onStart()方法。如果调用startService()方法前服务已经被创建,多次调用startService()方法并不会导致多次创建服务,但会导致多次调用onStart()方法。采用startService()方法启动的服务,只能调用Context.stopService()方法结束服务,服务结束时会调用onDestroy()方法附代码

2.Context.bindService()方式启动:①Context.bindService()方式的生命周期: 绑定时,bindService -> onCreate() –> onBind()调用者退出了,即解绑定时,Srevice就会unbindService –>onUnbind() –> onDestory()Context.bindService()方式启动 Service的方法:绑定Service需要三个参数:bindService(intent, conn, Service.BIND_AUTO_CREATE);第一个:Intent对象第二个:ServiceConnection对象,创建该对象要实现它的onServiceConnected()和 onServiceDisconnected()来判断连接成功或者是断开连接第三个

package com.dada.test;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.dada.test.BindService.MyBinder;

public class TestActivity extends Activity {
	
	private boolean flag;
	private static final String TAG = "TestActivity";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
 
        Button btnStart = (Button) findViewById(R.id.btnStart); 
 
        Button btnStop = (Button) findViewById(R.id.btnStop); 
 
        
        btnStart.setOnClickListener(new View.OnClickListener() { 
            @Override 
            public void onClick(View v) { 
            	//启动service 方式2
            	bindService();
            } 
        }); 
        
        btnStop.setOnClickListener(new View.OnClickListener() { 
        	 
            @Override 
            public void onClick(View v) { 
 //停止service 方式2
            	unBindService();
            } 
        }); 
    }
    
    //启动service 方式2
    //
    private void bindService(){
        Intent intent = new Intent(TestActivity.this,BindService.class);
        Log.i(TAG, "bindService()");
        bindService(intent, conn, Context.BIND_AUTO_CREATE);
    }
    
    private void unBindService(){
    	Log.i(TAG, "unBindService() start....");
        if(flag == true){
        	Log.i(TAG, "unBindService() flag");
            unbindService(conn);
            flag = false;
        }
    }
    
private ServiceConnection conn = new ServiceConnection() {
        
        @Override
        public void onServiceDisconnected(ComponentName name) {
            // TODO Auto-generated method stub
        	Log.i(TAG, "onServiceDisconnected()");
        }
        
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            // TODO Auto-generated method stub
        	Log.i(TAG, "onServiceConnected()");
            MyBinder binder = (MyBinder)service;
            BindService bindService = binder.getService1();
            bindService.MyMethod();
            flag = true;
        }
    };
}

抱歉!评论已关闭.