Skip to content

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

TipDescription
Compress ImagesServe optimized images from CDN
Enable CachingConfigure proper cache headers
Use CDNDeploy to CloudFlare, Vercel, Netlify
Lazy LoadDefer loading below-fold content

Offline Support

For offline functionality:

  1. Service Workers: Cache web assets
  2. Local Storage: Store user data locally
  3. 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:

  1. Open DevTools → Network tab
  2. Select "Fast 3G", "Slow 3G", or "Offline"
  3. 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

Released under the MIT License.