Network Considerations
Understanding network behavior is crucial for a smooth user experience in your Bagisto Native Android app.
Network States
1. Online
When the device has internet connectivity:
- WebView loads normally
- API calls work
- Real-time data syncs
2. Offline
When there's no internet:
- WebView shows cached content (if configured)
- Offline pages can be displayed
- Queue actions for later sync
Handling Network Changes
kotlin
// Network connectivity observer
class NetworkObserver(private val context: Context) {
private val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
fun isNetworkAvailable(): Boolean {
val network = connectivityManager.activeNetwork
val capabilities = connectivityManager.getNetworkCapabilities(network)
return capabilities?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) == true
}
}CORS Configuration
Your web server must allow CORS requests from your Android app:
javascript
// Example: Next.js headers configuration
// next.config.js
module.exports = {
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'Access-Control-Allow-Origin',
value: '*' // Or your specific Android app bundle identifier
}
]
}
]
}
}Performance Tips
| Tip | Description |
|---|---|
| Compress Images | Serve optimized images from CDN |
| Enable Caching | Configure proper cache headers |
| Use CDN | Deploy to CloudFlare, Vercel, Netlify |
| Lazy Load | Defer loading below-fold content |
Offline Support
For offline functionality:
- Service Workers: Cache web assets
- Local Storage: Store user data locally
- Background Sync: Queue actions when online
javascript
// Register service worker for offline support
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}Testing Network Conditions
Use Android's Network emulator:
- Open DevTools → Network tab
- Select "Fast 3G", "Slow 3G", or "Offline"
- Test app behavior under different conditions
Security Considerations
- Always use HTTPS in production
- Validate SSL certificates - don't disable SSL verification
- Don't expose sensitive data in URLs
- Use secure tokens for authentication
